Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

script works perfectly fine in studio mode but doesn't in the actual game. Please help?!

Asked by 7 years ago

I have a script that is supposed to punch whenever the f key is pressed, it works perfectly fine when I test it in studio mode, however, when I test it in the actual game it still does the animation but doesn't do any damage, and i'm not getting any errors in the output, so I don't know what is wrong with it. Please help.

This is the script that detects if the button is pressed and does the animation, it is a local script:

plr = game.Players.LocalPlayer
if plr.Character == nil then 
    repeat wait() until plr.Character ~= nil
end
char = plr.Character
debounce = false

function onKeyPress(input)
    if debounce == true then return end
    if input.KeyCode == Enum.KeyCode.F then 
        debounce = true
        a = Instance.new("Animation") 
        human = char:FindFirstChildOfClass("Humanoid")
        hitscript = script.Hit:Clone()
        hand = char:FindFirstChild("RightHand")
        arm = char:FindFirstChild("Right Arm")
            a.AnimationId = "rbxassetid://1056939487"
            a2 = human:LoadAnimation(a)
            a2:Play() 
            hitscript.Parent = hand
        end
        hitscript.Disabled = false
        wait(1)
        hitscript:Destroy() 
        debounce = false
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

This is the script that does the damage, it is a server script that is the child of the local script:

debounce = false

script.Parent.Touched:Connect(function(hit)
    if debounce == true then return end
    h = hit.Parent:FindFirstChildOfClass("Humanoid")
    if h then
        if hit.Parent.Name == script.Parent.Parent.Name then return end
        debounce = true
        h:TakeDamage(5)
        s = Instance.new("Sound", script.Parent)
        s.SoundId = "rbxassetid://329077052" 
        s.PlayOnRemove = true
        s:Destroy()
        wait(1)
        debounce = false
    end
end)
0
On line 6 you did an if statement to check if it found the humanoid, but you never did one if it was not there. Since you hit the a player's many times and you turn the debounce off once it hits one part, you might not hit the humanoid. You could do an else statement to make sure it gets hit that time and then precede with the other stuff. yougottols1 420 — 7y
0
Check it hit an accessory! hiimgoodpack 2009 — 7y
0
Do you have FE on? lukeb50 631 — 7y
0
Make sure it didnt hit an accessory, or any other part in the humanoid. As hiim said. Accessory[hat etc] H4X0MSYT 536 — 7y

Answer this question