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...
local Players = game:GetService("Players") local Player = game.Players.LocalPlayer local FlowerBasket = game:GetService("ReplicatedStorage"):WaitForChild("FlowerBasket") local Backpack = Player:FindFirstChild("Backpack") wait(2) Players.PlayerAdded:Connect(function() if script.Parent.Username.Value == "543752773" then Backpack.FlowerBasket:Clone() end 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
game:GetService("ReplicatedStorage"):WaitForChild("FlowerBasket")
such as
Basket = game:GetService("ReplicatedStorage"):WaitForChild("FlowerBasket")
and after the cloning part add the .Parent
Basket:Clone() Basket.Parent = Backpack
as i notice you used
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
Players.PlayerAdded:Connect(function(player) 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:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local FlowerBasket = ReplicatedStorage:WaitForChild("FlowerBasket") game.Players.PlayerAdded:Connect(function(player) if player.UserId == yourUserId then -- Your userid should NOT be a string, it's a number so it will be fine FlowerBasket:Clone().Parent = player:WaitForChild("Backpack") end end)