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

Why isn't my on spawn script not functioning?

Asked by
ferano 0
8 years ago
Edited 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Works locally but not in server, tried many things and error line is 4, with code "attempt to index local 'player' (a nil value)". Script is below.

function onRespawned2(player)
local player = game.Players.LocalPlayer
local Character = player:FindFirstChild("Character")

local pft = script.savedarmor:Clone()
pft.Parent = player.Character
player.Character.Humanoid.WalkSpeed = 0
pft.Disabled = false
end                                                                                                                                                                                                                                                                                                                                                                                                                                                             

function onSpawned(newPlayer)
wait(1)
onRespawned2(newPlayer) 
newPlayer.Changed:connect(function (property)
    if (property == "Character") then

        onRespawned2(newPlayer) 
        local gui = script.Armorgui:Clone()
    end
end)
while true do
    if newPlayer.Character ~= nil then break end
    wait()
end
end

game.Players.PlayerAdded:connect(onSpawned)
1
LocalPlayer can't be used in a serverside script, I don't see a reason to reassign player on line two, removing that line should fix the error. http://wiki.roblox.com/index.php?title=API:Class/Players/LocalPlayer Prohibetur 70 — 8y
0
Never said it wasn't server side, your response was no help... I ended up fixing it on my own, thank you anyways. ferano 0 — 8y

Answer this question