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

error - ServerScriptService.print:2: attempt to index nil with 'Character' what i can do ?

Help. script :

game:GetService('ReplicatedStorage').Print.OnServerEvent:Connect(function(plr)
hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
hum.WalkSpeed = 100
end)

1 comment

0

Put your script inside a code block to make it easier for us to read.

2 answers

✓ Accepted answer

You’re trying to reference a Local Instance from a Server, that of which is a global space; the Server doesn’t have a "LocalPlayer". This Object path can only be Index through a LocalScript as these programs operate on the Local Machine, which means they’re aware of which Client they are.

This isn’t much of a roadblock though, fortunately, the .OnServerEvent signal contains the Player Object that invoked the Event, we can simply just use that:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("Print")

RemoteEvent.OnServerEvent:Connect(function(Player)
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local Humanoid = Character:FindFirstChildOfClass("Humanoid")
    if (Humanoid) then
        Humanoid.WalkSpeed = 100
    end 
end)

If this works, don’t forget to accept this answer!

Try this code:

game:GetService('ReplicatedStorage').Print.OnServerEvent:Connect(function(plr)
hum = plr.Character:WaitForChild("Humanoid")
hum.WalkSpeed = 100
end)

1 comment

0

wow u insane! thanks bro

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