Hey! I’m trying to make a script so when the scripts parent is clicked, a tool is cloned from Lighting to the players backpack. It won’t work, can someone help please?

I do not really find any problem in your code.
Try this:
local clickDetector = script.Parent; -- Referencing the click detector
local requiredTeam = game.Teams.Blue -- Redefine this.
function mouse_Click(player)
if player.Team ~= requiredTeam then return end; -- If the player's team isn't equal to the required team, then stop the function.
local spikes = game.Lighting["Spike Strip"]:Clone(); -- Cloning the spikes
spikes.Parent = player.Backpack -- Parenting the spikes
end;
clickDetector.MouseClick:Connect(mouse_Click) -- Connecting the event
Edit: Just tested a thing with non-capital letters parent, and it didn’t cause any error.
First of all, I suggest you use server storage instead of lighting.
Also the problem is you said parent instead of Parent
Just tested a thing with non-capital letters parent, and it didn’t cause any error.
Although that, you are right, it is recommended to store items in ServerStorage.
Is this being done in a server script or a local script?
I tried this with a couple changes, still didn’t work.
local requiredTeam = game.Teams.Civilian -- Redefine this.
function mouse_Click(player)
if player.Team ~= requiredTeam then return end; -- If the player's team isn't equal to the required team, then stop the function.
local spikes = game.ServerStorage["Spike Strip"]:Clone(); -- Cloning the spikes
spikes.Parent = player.Backpack -- Parenting the spikes
end;
clickDetector.MouseClick:Connect(mouse_Click) -- Connecting the event
Server script in the workspace.
Does it error anything in the output?
are you changing your team through local or server? if local then the server will not see it.
Nope, nothing comes up in output.
local Tool = game:GetService("ServerStorage").Tool -- Change This to the location of your tool
local TeamColour = BrickColor.new("New Yeller")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player.TeamColor == TeamColour then
local Spikes = Tool:Clone()
Spikes.Parent = player.Backpack
end
end)
Just tested this code and it works perfectly fine. Make sure you tool is in server storage and the script is a server script
Are you sure this is the script’s issue? I don’t see any errors. Maybe there’s something wrong with something else, which could be interfering. I just tested this in studio and it worked.
Make sure the script is in the part and there’s a working ClickDetector in it maybe.
sec_dude is most likely correct. The code works perfectly fine therefore this is most likely an issue with your team change system as the script requires you to have the team colour of “New Yeller”
Are you sure your team system works correctly?
Hey there!
If it’s not throwing errors it’s probably to do with the player’s TeamColor, since there’s no way to tell if the first if function returns false, and if it did it wouldn’t error out. Make sure the player’s team is the exact color and that they have the right team given to them. Also, since changing the color of the team would break the script, you might also want to compare the team’s name instead. You might also want to add some debug print statements for now to tell what the issue is.
Hope this helps! ![]()
This worked thank you! Sorry for the late response, I have been developing for 18 hour straight and needed to eat lol.