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

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

Asked by 1 year ago
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

Log in to vote
1
Answered by
Xyternal 247 Moderation Voter
1 year ago

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()
0
thanks. I solved the problem right after posting. But thanks anyway HeroFigo 81 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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

Answer this question