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

Changing character properties not working?

Asked by
vkax 85
6 years ago
local listtochange = {
    "WalkSpeed",
    "JumpPower"
}

local change = game.ReplicatedStorage:WaitForChild("ChangeProperty")
change.OnServerEvent:connect(function(property,player)
    game.Players[player].Character.Humanoid[property]=0
end)

game.Players.PlayerAdded:connect(function(player)
    wait(1)
    player.CharacterAdded:connect(function()
    for i,v in pairs(listtochange) do
        change:FireServer(v,player.Name)
    end
    end)
end)

^ That's my script, I get this output:

19:20:05.401 - WalkSpeed is not a valid member of Players 19:20:05.402 - Stack Begin 19:20:05.403 - Script 'ServerScriptService.Change', Line 3 19:20:05.403 - Stack End 19:20:05.403 - JumpPower is not a valid member of Players 19:20:05.403 - Stack Begin 19:20:05.404 - Script 'ServerScriptService.Change', Line 3 19:20:05.404 - Stack End

Can somebody help me with this? Thanks.

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

RemoteEvents only allow server-communication, they do not allow you to execute code in the same script, neither in a script that's derived from the same class where the event was created.

Here's what you could use:

function dostuff(property, player)
       game.Players[player].Character.Humanoid[property] = 0
end

game.Players.ChildAdded:Connect(function(player)
        wait(1)
        dostuff('WalkSpeed', player.Name)
        dostuff('JumpPower',player.Name)
end)
Ad

Answer this question