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

Script to Give Hats to Specific Player on Spawn Only Works in Studio?

Asked by 8 years ago

I am still really new at this game and have never done any scripting before, so I have no idea if there is a better way to do this or what.

I am trying to make it so that when a specific player joins they spawn with some hats I added to a model inside ServerStorage. It works perfectly fine in studio, but gives me an error in online mode.

This is the error I get in the console in online mode: ServerScriptService.OnlinePlayerHat: 1: attempt to index a nil value
Stack Begin Script 'ServerScriptService.OnlinePlayerHat', Line 1
Stack End

This is the script: (Yes, I switch "Player" with my username before I play it in online)

repeat wait() until game.Players:findFirstChild("Player").Character


GiveHats = true

Char = game.Players:findFirstChild("Player").Character

wait()

if GiveHats then
    for index, child in pairs(game.ServerStorage.Hats:GetChildren()) do
        child:Clone().Parent = Char
    end
end

I also uncopylocked my place if you want to look at it and get a better understanding of what I am trying to do since you can see it work in studio mode. http://www.roblox.com/games/201535173/FluxBloxs-Place

It would be nice if someone could either fix this, or give me a simpler script that actually works the same as what this does in studio mode.

(Sorry if anyone saw this already, I deleted the original post I had of it so I could try to get it working again, but still keep getting the same issue)

1 answer

Log in to vote
0
Answered by 8 years ago

Add this to the very top

wait(.5)
0
Already tried that, it still only worked in studio. FluxBlox 0 — 8y
0
Chang e it to wait(.5) that should work User#5978 25 — 8y
Ad

Answer this question