I created a script to clone a model to the player on every spawn, yet when I test it ingame, it brings up an error saying “Check your internet connection and try again” every single time. Disabling the script makes the game work fine, however testing inside studio, crashes all my windows, and force quits studio.
while true do game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) local sphere = game.ReplicatedStorage.TheSphere:Clone() sphere.Parent = char.Torso wait(10) sphere:Destroy() end) end) end
Un Lua-d script:
while true do
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local sphere = game.ReplicatedStorage.TheSphere:Clone()
sphere.Parent = char.Torso
wait(10)
sphere:Destroy()
end)
end)
end
Any help is appreciated, as this is a bit of an important task for the script to do.
You don’t need the while true do loop - the event fires every time a player joins the game.
However, you’ll need to account for if a player dies and respawns, because it completely changes the character. You should check out the Humanoid.Died event, and maybe add in a CharacterAdded there as well.
You should probably move the code inside the .Died event into a separate function, and call the function twice, one time when the character is added the first time (in between CharacterAdded and Died) and when the character dies (inside the Died).
The question that I don’t know the answer to is whether or not it’ll work after multiple respawns, because when the player dies, the character is completely remade (so the old char that your script refers to technically doesn’t exist anymore).
By the way, does this need to be on the Server side? It would be 10x easier if you made it a LocalScript and put it inside StarterCharacterScripts (that will run every time a character is added, either when joining or after respawning). It just might not show up for other players.