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

Why does my player keep sprinting after I delete a script?

local UserInputService = game:GetService("UserInputService")
local btn = script.Parent
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

-- A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 26
        btn.BackgroundColor3 = Color3.new(0.0352941, 0.972549, 0.458824)
    end
end

local function onInputEnded(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
        btn.BackgroundColor3 = Color3.new(0.12549, 0.207843, 0.972549)
    end
end

local function bten()
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 26
    btn.BackgroundColor3 = Color3.new(0.0352941, 0.972549, 0.458824)
end

UserInputService.InputBegan:Connect(onInputBegan)
UserInputService.InputEnded:Connect(onInputEnded)
btn.Activated:Connect(bten)

I made a little sprinting script that get's inserted in the clients during a round. And get's deleted when round ends. AFTER I delete it I set the speed of the players to 16 again but it doesn't work

2 answers

✓ Accepted answer

If you want your local script to work for everyone, you will have to use a Remote Event, and then call it from a serverscript. For say, if you insert a Remote Event in Replicated Storage, your code will look something like this.

ServerScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")

 

	remoteEvent:FireAllClients()

Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
 

remoteEvent.OnClientEvent:Connect()

1 comment

0

thanks. I solved the problem right after posting. But thanks anyway

It's a local script so it changes the walkspeed locally....

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