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

How come script is not firing correct value?

Asked by 6 years ago

Ok, so basically I was making a pretty simple eating system and I want to make it filtering enabled compatible but when it fires the event the walkspeed of the player turns to 0 instead of the value fired which is 20. Here are the scripts

Local Script inside tool

local rs = game:GetService("ReplicatedStorage")


local player = game.Players.LocalPlayer
script.Parent.Equipped:Connect(function()
    game:GetService("UserInputService").InputBegan:Connect(function(inputObject , gameProcessedEvent)
        if inputObject.KeyCode == Enum.KeyCode.R then
        local regen = 20
            rs.RemoteEvents.Eat:FireServer(regen)
            script.Parent:Destroy()
        end
    end)
end)

Server Script:

local rs = game:GetService("ReplicatedStorage")
rs.RemoteEvents.Eat.OnServerEvent:Connect(function(player, regen)
    print("dank memes")
    local playerworkspace = game.Workspace:FindFirstChild(player.Name)
    if playerworkspace:FindFirstChild("Humanoid") then
        playerworkspace.Humanoid.WalkSpeed = regen
        wait(5)
        playerworkspace.Humanoid.WalkSpeed = 16
    end
end)

I would appreciate it if you could help!

2
just do player.Character, dont look for them in workspace Gey4Jesus69 2705 — 6y
0
Yeah but the value regen is still not firing properly The_sandwic 14 — 6y
1
I just tested this and it worked fine. Are you sure a separate script isn't setting the player's walkspeed? call23re2 87 — 6y
0
just leave the regen part and just set walkspeed to 20 DumbKickButt5588 167 — 6y
0
If I want different foods with different values then what will I do? The_sandwic 14 — 6y

Answer this question