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

How can I make sure that a player will respawn with gear?

Asked by 4 years ago
Edited 4 years ago

I'm making a shop that allows you to buy gear but when the player resets the gear they bought is no longer there. How can I stop this from happening and how can I make sure that they spawn with the gear?

a.Parent = player.Backpack
a.Parent = player.StarterGear

This part of my code seems to be the issue but I'm not sure why?

1 answer

Log in to vote
0
Answered by
crywink 419 Moderation Voter
4 years ago

Hey!

Looks like you're on the right track so far. If you want to have somebody spawn with a tool, you can just add the tool to said players' starter gear by parenting it. An example is shown below...

local tool = game.ServerStorage.Tool -- just an example tool; dont use this exact code lol

tool:Clone().Parent = player.StarterGear

If this isn't enough for you and you want to do more before giving the tool, you can give it to them when they spawn with the CharacterAdded event. This will fire off whenever, well, the character is added. I'll show a code example for that below as well.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect (function(plr) -- This will get called whenever a new player joins.
    plr.CharacterAdded:Connect (function(character) -- Add our CharacterAdded listener
        local tool = game.ServerStorage.Tool

        tool:Clone().Parent = player.Backpack -- Parent it to the backpack this time.
    end)
end)

If you have any additional questions, feel free to ask.

If this answer helped, please remember to accept it! :)

0
Thank you for the help but I figured out the problem that I'm having and it's because I can't add a gear to StarterGear via LocalScript. How do I get around this because the code is in a GUI? Michael_TheCreator 166 — 4y
0
You can use a RemoteEvent to tell the server to add it for you. @Michael_TheCreator crywink 419 — 4y
Ad

Answer this question