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

How can i make this spell only be used by the caster?

This small script is used to change the walk speed of a target but i want to make it so its self inflict and works only on the person who casted the spell. How would i go by doing that?

function onActivation()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 26
wait(8)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 17
wait()
end	
script:Destroy()

1 comment

0

Which spell?

1 answer

✓ Accepted answer

If that's on a local script, you wont be able to change other players walkspeed and jumppower, only yours, so there is no problem there.

If it's a server script (which doesnt seem to be, because you are using LocalPlayer) then you will have to use Remote Events or Remote Functions. Because events fired from these objects always have their first parameters set to be the player who fired the event, there is no way for players to hack it by choosing another target for the spell, as long as you do use that first variable.

Example: --localscript TextButton.MouseButton1Click:Connect(function() workspace.RemoteEvent:FireServer(game.Players.PLAYERNAME) end)

--serverscript workspace.RemoteEvent.OnServerEvent:Connect(function(player) print(player.Name) end)

If you use this code you will see that even if you send a specific player as target to server, the server will print your name instead of the target (PLAYERNAME). If you do set a second parameter on the server, it will be that target you wrote cliend side:

--localscript TextButton.MouseButton1Click:Connect(function() workspace.RemoteEvent:FireServer(game.Players.PLAYERNAME) end)

--serverscript workspace.RemoteEvent.OnServerEvent:Connect(function(player,target) print(target.Name) end)

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