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

attempt to index global 'yourRemoteEvent' (a nil value) Why tho?

So I'm trying to add a shift to sprint script but it keeps stopping after a few seconds so I tried this to maybe fix it but now im getting this

game:GetService("UserInputService").InputBegan:Connect(function(input) -- Input Began checks if the play presses anything and fires whenever the player does so

if input.KeyCode == Enum.KeyCode.LeftShift then -- Detects LS press

-- Fire a remote event

yourRemoteEvent:FireServer()

end

end)

game:GetService("UserInputService").InputEnded:Connect(function(input)

--Send another remote event to stop Bool Value when enabled

end)

This is also my sprint script in case it can be fixed in there instead

-- Define Vars

local player = game.Players.LocalPlayer

local Character = player.Character

local UserInputService = game:GetService("UserInputService")

local Speed = 25

-- Script

UserInputService.InputBegan:Connect(function(key)

if key.KeyCode == Enum.KeyCode.LeftShift then

Character.Humanoid.WalkSpeed = Speed

-- Do This Scrpt

end

end)

UserInputService.InputEnded:Connect(function(key)

if key.KeyCode == Enum.KeyCode.LeftShift then

Character.Humanoid.WalkSpeed = 16

end

end)

1 answer

You're not defining what 'yourRemoteEvent' really is. It's just... a nil variable. To fix your problem your going to need to set a variable to the remoteevent before actually calling on it.

3 comments

0

Thanks I ended up going with a different sprint script because I wanted it to take away stamina also but now im getting this error attempt to index local 'data' (a number value)

0

this is the full script its from local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE") RE.OnServerEvent:connect(function(player, request, data) if request == "sprint" then player.Character.Humanoid.WalkSpeed = data(1) end end)

0

your 2nd argument on the client side needs to be data and not a nil value

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