I’ve been trying to change a player’s walkspeed by doing a Remote Event (from client to server). I’ve been getting this error, however:
"attempt to index nil with ‘Connect’
I have two scripts; one a localscript in the StarterPlayerScripts folder and a script in the ServerScriptService
Here is the local script:
-- local teamService = game:GetService("Teams");
local toggleSpeedChange; -- Variable for changing player speed when the player has switched to the Spectators team
local player = game.Players.LocalPlayer;
local characterModel = player.Character or player.CharacterAdded:wait();
local character = characterModel:WaitForChild("Humanoid");
local replicatedStorage = game:GetService("ReplicatedStorage");
local changePlayerWalkSpeedEvent = replicatedStorage:WaitForChild("ChangePlayerWalkSpeedEvent");
print("TEST");
for _, team in pairs(teamService:GetTeams()) do
team.PlayerAdded:connect(function(player) -- Every time a player is added onto a team
changePlayerWalkSpeedEvent:FireServer(100);
end)
end
Here is the server script:
--
local replicatedStorage = game:GetService("ReplicatedStorage");
local changePlayerWalkSpeedEvent = Instance.new("RemoteEvent", replicatedStorage);
changePlayerWalkSpeedEvent = "ChangePlayerWalkSpeedEvent";
local function onChangePlayerWalkSpeedFired(player, walkSpeed)
player.Humanoid.WalkSpeed = 100;
end
changePlayerWalkSpeedEvent.OnServerEvent:Connect(onChangePlayerWalkSpeedFired);
I’m also getting a warning message saying:
Infinite yield possible on 'ReplicatedStorage:WaitForChild(“changePlayerWalkSpeedEvent”)
I can’t seem to work around this error message to allow the client to change its walk speed using a Remote Event.