When i equip the perks it equip to all can someone help me to only give it to person who equip.
local Player = game.Players.LocalPlayer
local player = game.Players.PlayerAdded:Connect(function(player)
local Character = player.CharacterAdded:Connect(function(Character)
game.ReplicatedStorage.TrailScripts.Equip.Golden.OnServerEvent:Connect(function(Player)
--[[local MutatorsFolder = Player:WaitForChild("HeadStats")
for i, v in pairs(MutatorsFolder:GetChildren()) do
v.Value = 0
end--]]
local Golden = game.ReplicatedStorage.Trails.Golden:Clone()
local Parents = Golden.Attachment
Parents.Parent = Character.Torso
Player:WaitForChild("BodyStats").Golden.Value = 0
end)
end)
end)
To be clear, do you want this to run when a player joins the game, or when the RemoteEvent is fired?
I’ve already spotted a lot of issues with you code, which I will outline once I understand how you want the code to work. It looks like you’re using PlayerAdded but you’re also using a RemoteEvent (hence OnServerEvent) so I’m wondering whether you want the code to run when a player joins or when the Remote is fired.
why do you have the onserverevent under playeradded and characteradded events? Of course its gonna give to everyone because when you fire to the server, everyone a part of the characteradded event gets the server event the player parameter no longer means anything because its overridden by the character variable (which everyone currently on server will have and since its fired under everyone, everyone will get it)
Just separate the onserver event from the local character and player–i don’t understand why its under it in the first place…
However i fix my own problem but theres 1 more new bug
local Player = game.Players.LocalPlayer
game.ReplicatedStorage.TrailScripts.Equip.RemoteAlpha.OnServerEvent:Connect(function(player, Player)
local Character = player.Character or player.CharacterAdded:Wait()
local MutatorsFolder = player:WaitForChild("HeadStats")
for i, v in pairs(MutatorsFolder:GetChildren()) do
v.Value = 0
end
Player:WaitForChild("HeadStats").Alpha.Value = 0
if Character.Head:FindFirstChild("Godly") then
Character.Head:FindFirstChild("Godly"):Destroy()
else
end
local Gui = game.ReplicatedStorage.Trails.Alpha:Clone()
Gui.Parent = Character.Head
end)
ServerScriptService.TrailHandler.Equips - Alpha.Equip - Trail:18: attempt to index nil with 'WaitForChild’
You have two player variables, one with a capital letter. First off, don’t do that because you can get confused and then this exact scenario happens. Second, delete all references to the capital Player and just use the lowercase one.
local players = game.Players.LocalPlayer
game.ReplicatedStorage.TrailScripts.Equip.RemoteAlpha.OnServerEvent:Connect(function(player,players)
local Character = player.Character or player.CharacterAdded:Wait()
local MutatorsFolder = player:WaitForChild("HeadStats")
for i, v in pairs(MutatorsFolder:GetChildren()) do
v.Value = 0
end
players:WaitForChild("HeadStats").Alpha.Value = 0
if Character.Head:FindFirstChild("Godly") then
Character.Head:FindFirstChild("Godly"):Destroy()
else
end
local Gui = game.ReplicatedStorage.Trails.Alpha:Clone()
Gui.Parent = Character.Head
end)
You still shouldn’t have your variables named so similarly.
This doesn’t work at all in a server script, you can delete this. It does literally nothing and deleting it won’t affect your code in any way.
If this is line 18 (you forgot to specify which line was which) then it means players is nil. Your issue then is with the script calling the remote event.