So I decided to make a code that allows only me, no one else to be able to get a certain gear in game. Here is the script...
01 | local Players = game:GetService( "Players" ) |
02 | local Player = game.Players.LocalPlayer |
03 | local FlowerBasket = game:GetService( "ReplicatedStorage" ):WaitForChild( "FlowerBasket" ) |
04 | local Backpack = Player:FindFirstChild( "Backpack" ) |
05 | wait( 2 ) |
06 | Players.PlayerAdded:Connect( function () |
07 | if script.Parent.Username.Value = = "543752773" then |
08 | Backpack.FlowerBasket:Clone() |
09 |
10 | end |
11 | end ) |
I really need to stop trying to code at 3:00 in the morning its making me confused Its probably line 8, but I don't know how to fix that.
try assigning a variable to
1 | game:GetService( "ReplicatedStorage" ):WaitForChild( "FlowerBasket" ) |
such as
1 | Basket = game:GetService( "ReplicatedStorage" ):WaitForChild( "FlowerBasket" ) |
and after the cloning part add the .Parent
1 | Basket:Clone() |
2 | Basket.Parent = Backpack |
as i notice you used
1 | local Player = game.Players.LocalPlayer |
so that's a local script ... I suggest doing .PlayerAdded in a server script so when the server detects the player added it will clone the tool to the player backpack. If u want to get the player form server script the .PlayerAdded will give it to you as a parameter
1 | Players.PlayerAdded:Connect( function (player) |
2 | end ) |
Like @Mikael20143 said, you should use a server script in SSS (ServerScriptService) and put the tool or whatever inside RepStorage or ServerStorage, you can try checking the UserId instead of the Value thing:
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local FlowerBasket = ReplicatedStorage:WaitForChild( "FlowerBasket" ) |
3 |
4 | game.Players.PlayerAdded:Connect( function (player) |
5 | if player.UserId = = yourUserId then -- Your userid should NOT be a string, it's a number so it will be fine |
6 | FlowerBasket:Clone().Parent = player:WaitForChild( "Backpack" ) |
7 | end |
8 | end ) |