Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local Debris = game:GetService("Debris")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local remoteEvent = Instance.new("RemoteEvent")
- remoteEvent.Name = "ShowDamage"
- remoteEvent.Parent = ReplicatedStorage
- local function onRightClick(player)
- print("Right-click detected")
- local character = player.Character
- if not character then return end
- local humanoid = character:FindFirstChild("Humanoid")
- if not humanoid then return end
- local target = player:GetMouse().Target
- if not target then return end
- local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
- if not targetPlayer then return end
- local targetHumanoid = target.Parent:FindFirstChild("Humanoid")
- if not targetHumanoid then return end
- -- Play punch animation
- local animation = Instance.new("Animation")
- animation.AnimationId = "rbxassetid://13337873546"
- local animationTrack = humanoid:LoadAnimation(animation)
- animationTrack:Play()
- print("Playing punch animation")
- -- Apply damage to the target player
- targetHumanoid:TakeDamage(10)
- print("Applying damage to target player")
- -- Show damage on the target player's client
- remoteEvent:FireClient(targetPlayer, target, 10)
- end
- local function onPlayerAdded(player)
- player:GetMouse().Button2Down:Connect(function()
- onRightClick(player)
- end)
- end
- Players.PlayerAdded:Connect(onPlayerAdded)
- -- ServerScriptService
- local function onShowDamage(player, part, damage)
- print("Showing damage on client")
- local damageLabel = Instance.new("BillboardGui")
- damageLabel.Adornee = part
- damageLabel.Size = UDim2.new(0, 100, 0, 50)
- damageLabel.StudsOffset = Vector3.new(0, 3, 0)
- local textLabel = Instance.new("TextLabel")
- textLabel.BackgroundTransparency = 1
- textLabel.Size = UDim2.new(1, 0, 1, 0)
- textLabel.TextColor3=Color3.new(1,0,0)
- textLabel.TextStrokeTransparency=0
- textLabel.TextScaled=true
- textLabel.Text="-"..tostring(damage)
- textLabel.Parent=damageLabel
- damageLabel.Parent=player.PlayerGui
- Debris:AddItem(damageLabel,1)
- end
- remoteEvent.OnServerEvent:Connect(onShowDamage)
- -- StarterPlayerScripts
- local function onShowDamageClient(part,damage)
- print("Showing damage on client")
- local player=Players.LocalPlayer
- local character=player.Character
- if not character then return end
- local humanoidRootPart=character:FindFirstChild("HumanoidRootPart")
- if not humanoidRootPart then return end
- local distance=(humanoidRootPart.Position-part.Position).Magnitude
- if distance>100 then return end
- local damageLabel=Instance.new("BillboardGui")
- damageLabel.Adornee=part
- damageLabel.Size=UDim2.new(0,100,0,50)
- damageLabel.StudsOffset=Vector3.new(0,3,0)
- local textLabel=Instance.new("TextLabel")
- textLabel.BackgroundTransparency=1
- textLabel.Size=UDim2.new(1,0,1,0)
- textLabel.TextColor3=Color3.new(1,0,0)
- textLabel.TextStrokeTransparency=0
- textLabel.TextScaled=true
- textLabel.TextStrokeColor3=Color3.fromRGB(255,255,255)
- textLabel.Font=Enum.Font.SourceSansBold
- textLabel.TextStrokeTransparency=0
- textLabel.TextSize=30
- textLabel.ZIndex=10
- textLabel.Text="-"..tostring(damage)
- textLabel.Parent=damageLabel
- damageLabel.Parent=player.PlayerGui
- Debris:AddItem(damageLabel,1)
- end
- remoteEvent.OnClientEvent:Connect(onShowDamageClient)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement