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 location in the game. It works perfectly fine in studio, but gives me an error in online mode. Yes, I switch "Player" with my username before I play it in online.
This is the error I get in the console in online mode: ServerScriptServer.OnlinePlayerHat:2: attept to index a nil value Stack Begin Script 'ServerScriptService.OnlinePlayerHat', Line 2 Stack End
This is the script:
ContentProvider = game:GetService("ContentProvider") repeat wait() until game.Players:findFirstChild("Player").Character ~= nil repeat wait() until (ContentProvider.RequestQueueSize == 0) Plr = game.Players:findFirstChild("Player") Char = game.Players:findFirstChild("Player").Character GiveHats = true wait(6) if GiveHats then for index, child in pairs(game.ServerStorage.Hats:GetChildren()) do child:Clone().Parent = Char end if GiveHats then for index, child in pairs(game.ServerStorage.Hats.Renni:GetChildren()) do child:Clone().Parent = Char end 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.
Put
repeat wait() until game.Players.LocalPlayer.Character
At the top, Reason is because studio is client sided so it loads character faster on server it doesn't load as fast so your script runs locally but server is trying to load so it makes errors.
ContentProvider = game:GetService("ContentProvider") repeat wait() until game.Players.LocalPlayer.Character ~= nil repeat wait() until (ContentProvider.RequestQueueSize == 0) Plr = game.Players.LocalPlayer Char = game.Players.LocalPlayer.Character GiveHats = true wait(6) if GiveHats then for index, child in pairs(game.ServerStorage.Hats:GetChildren()) do child:Clone().Parent = Char end if GiveHats then for index, child in pairs(game.ServerStorage.Hats:GetChildren()) do child:Clone().Parent = Char end end end
1) You were calling on "Player" which is only used as the RobloxStudio character name. LocalPlayer basically gets the player on the computer
2) In line 17, it should be
game.ServerStorage.Hats:GetChildren()