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

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

Asked by 4 years ago
Edited by Ziffixture 4 years ago

Help. script :

game:GetService('ReplicatedStorage').Print.OnServerEvent:Connect(function(plr)
hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
hum.WalkSpeed = 100
end)
0
Put your script inside a code block to make it easier for us to read. ScuffedAI 435 — 4y

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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!

Ad
Log in to vote
1
Answered by 4 years ago

Try this code:

game:GetService('ReplicatedStorage').Print.OnServerEvent:Connect(function(plr)
hum = plr.Character:WaitForChild("Humanoid")
hum.WalkSpeed = 100
end)
0
wow u insane! thanks bro DapperNarwhal 2 — 4y

Answer this question