Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why can't I change a players variables?

I am trying to change the WalkSpeed, the position, and a value but the script wont change it. After testing I found that the function works so it must be the code inside it.

Server Script:

game.ReplicatedStorage.CloseShop.OnServerEvent:Connect(function(player)
	game.Workspace[player.Name]:FindFirstChild("Humanoid").WalkSpeed = 16
	game.Workspace[player.Name].HumanoidRootPart.CFrame = game.Workspace.TPClosePart.CFrame
	wait(2)
	player.InShop.Value = false
end)

Local script:

game.ReplicatedStorage.CloseShop:FireServer()

2 comments

0

instead of searching for the player's name in the workspace just use Player.Character (https://developer.roblox.com/en-us/api-reference/property/Player/Character)

0

Also since this question was answered when we were in chat please add [Solved] to the title

1 answer

The first parameter of the OnServerEvent is always the player that fired it so you can simply get the character directly from it

so what you can do is:

game.ReplicatedStorage.CloseShop.OnServerEvent:Connect(function(player)
	local character = player.Character
  	local humanoid = character:WaitForChild("Humanoid")
	humanoid.WalkSpeed = 16
	character.HumanoidRootPart.CFrame = workspace.TPClosePart.CFrame
    wait(2)
    player.InShop.Value = false
end)

7 comments

0

This doesn't work

0

Oh, sorry. Any output errors?

0

Anton wouldn't you do SetPrimaryPartCFrame? Just a suggestion.

0

I do that I just wanted to maintain his script the way it was

0

no errors

0

Ok are you sure the localscript that is firing the event is working properly?

0

Yes I used a print and it did print, also I did get teleported

This discussion is preserved as it was. New answers, comments, and votes are closed.