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

How do you make someone spawn with (x) if they own (z)?

Asked by 10 years ago

http://www.roblox.com/Spawn-With-Darkheart-item?id=162498217

If they buy this, how do I make it so in-game, they always spawn with darkheart?

Thanks.

0
I'm having some confusion at the end: What do you mean by all that clone stuff? 1) What do I clone, 2) Do I put this script in Workspace, in the sword, in ServerStorage, or in Backpack? Thanks. JustGimmeDaBux 18 — 10y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Clone() is a method that, well, clones things. It will make an exact copy of an instance and all it's children.

As you can see, below I am cloning the sword that we put in ServerStorage. I am then putting the copy of the sword in the player's backpack.

And yes, you can put the script in workspace, but putting it in ServerScriptService would be more efficient.

What I would do is put a Darkheart sword in ServerStorage. (ServerStorage is more efficient than Lighting).

First, we need to get the GamePassService. We can do this by using the GetService() method of game.

GPS = game:GetService("GamePassService")
passId = 000000 --Change to the pass ID

Then, create a new function that will check if a player has the pass.

passId = 000000 --Change to the pass ID
GPS = game:GetService("GamePassService")

function PlayerHasPass(player)

end

To actually do the checking, we must use the PlayerHasPass method of GamePassService. If the player has the pass, it will return true. If not, it will return false. Therefore if we return GPS:PlayerHasPass(player, passId) we can check if it returned true, or if it returned false easily with an if statement.

passId = 000000 --Change to the pass ID
GPS = game:GetService("GamePassService")

function PlayerHasPass(player)
    return GPS:PlayerHasPass(player, passId)
end

The final part is just a simple PlayerAdded event. When a player joins the game, we will use the function we just created to check if they have the pass, and if they do, give them the sword we put in ServerStorage.

passId = 000000 --Change to the pass ID
GPS = game:GetService("GamePassService")

function PlayerHasPass(player)
    return GPS:PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:connect(function(player)
    if PlayerHasPass(player) then
        local dh = game.ServerStorage.Darkheart:Clone() --Clone it
        dh.Parent = player.Backpack --Put the clone in the Player's backpack. If you want the player to keep it after death make a new clone and put it in StarterGear as well.
    end
end)

Hope i helped!

Ad

Answer this question