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

How to make a script give something, an item or money only once in first time join only?

Asked by 5 years ago
Edited 5 years ago

For example, a starter sword that I only want to be given out on first join (as it will be saved by data store) so it will not duplicate on next joins.

--current give code--
function onJoin()
    local start = game.Lighting.StarterSword:Clone()
    start.Parent = player.Inventory
end

Do I need to create a bool value that in the player that will save on the datastore to indicate if a tool has been given already or not? or is there a simpler way?

1 answer

Log in to vote
0
Answered by 5 years ago

When a player leaves, its descendants and character will be removed as well. No need to worry about that. Also, don't use Lighting to store things. The only objects that should go there are skyboxes and post effects. I don't think a sword is a skybox or post effect.

--current give code--
function onJoin(player)
    local start = game:GetService("ServerStorage").StarterSword:Clone()
    start.Parent = player.Backpack
    start:Clone().Parent = player.StarterGear
end

game:GetService("Players").PlayerAdded:Connect(onJoin)
Ad

Answer this question