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.
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!