I was making a punch script that everytime you press q the script in serverscriptservice has to choose an punch animation to play. The game is Filtering Enabled and is using R15. The reason why it's made this way is because I'm using another LocalScript in StarterGui to increase the value of the IntValue after a player transforms.
When I test the script in test mode, it works perfectly fine. However when i test it in the actual game the entire script plays but it doesn't damage the dummy.
LocalScript (StarterCharacterScripts)
local uis = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local plr = game.Players.LocalPlayer
local char = plr.Character
local ready = true
local damageValue = Instance.new("IntValue", char)
damageValue.Name = "Damage"
damageValue.Value = 15
local function punch(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.Q and ready then
punchEvent:FireServer()
ready = false
wait(0.5)
ready = true
end
end
uis.InputBegan:Connect(punch)
Script (ServerScriptService)
math.randomseed(tick())
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"
local animations = {1226591696, 1226673643}
local function onPunchFired(plr)
local char = game.Workspace:FindFirstChild(plr.Name)
local humanoid = char.Humanoid
local anim = Instance.new("Animation")
local picked = math.random(1, #animations)
anim.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
local animTrack = humanoid:LoadAnimation(anim)
animTrack:Play()
local damageScript = script.DamageScript:Clone()
if picked == 1 then
damageScript.Parent = char.RightHand
elseif picked == 2 then
damageScript.Parent = char.LeftHand
end
damageScript.Disabled = false
wait(0.4)
damageScript:Destroy()
end
punchEvent.OnServerEvent:connect(onPunchFired)
Damage Script (Inside of the script above)
script.Parent.Touched:connect(function(hit)
local char = hit.Parent
local chara = script.Parent.Parent
local dmg = chara:FindFirstChild("Damage")
local humanoid = char:FindFirstChild("Humanoid")
if humanoid and char.Name ~= script.Parent.Parent.Name and dmg then
humanoid.Health = humanoid.Health - dmg.Value
script.Disabled = true
wait(0.5)
script.Disabled = false
end
end)
