Player gets a second weapon when another player spawns

Hello! I’m trying to make a script where when you spawn in you get your weapon. But when another player spawns in, the first player who spawns gets a second tool.
I’ve tried making an if statement preventing that from happening

Script
Screenshot 2023-02-04 at 13.52.52

Also it’s a local script in startergui, so you know.

Can you copy and paste the script here.
And also use the preformatted text when showing code so its easier to fix problems, just click on it and you will be able to paste the code in it

local touched = false
function touch()
	local Player = game.Players.LocalPlayer
	if not Player.Character:FindFirstChildWhichIsA("Tool") then
		wait(1)
		print(Player)
		print(Player.PlayerGui)
		print(Player.PlayerGui.Weapons)
		print(Player.PlayerGui.Weapons.RockEquipped)
		print(Player.PlayerGui.Weapons.RockEquipped.Value)
		print(Player.PlayerGui.Weapons.RockEquipped.Value == true)
		if Player.PlayerGui.Weapons.RockEquipped.Value == true then
			game.Workspace.Lobby.Show.Rock.Handle.Anchored = false
			game.Workspace.Lobby.Show.Rock.Handle.Transparency = 0
			game.Workspace.Lobby.Show.Rock.Parent = Player.Backpack
		end 	
	end	
end	
game.Workspace.SpawnIn.Touch.Touched:Connect(function()
	if not touched then
		touched = true
		touch()
		wait(2)
		touched = false
	end		
end)
1 Like

Do you get any errors, what part of your demand does the script not do?

It does everything right, it just gives the player that spawned first, another rock (weapon) when another player spawns.
I think this line isn’t working properly:
if not Player.Character:FindFirstChildWhichIsA(“Tool”) then

You have to rewrite your whole script from what I understand or put the tool to starterpack but if you are willing to make a script you have to make a new script that is not a localscript in serverscriptservice
And put this in it:

game.Players.PlayerAdded:Connect(function(Player)
	local tool = (Your Tool):Clone()
	tool.Parent = Player.Backpack
	tool.Equipped:Connect(function()
		--Code
	end)
end)

I can’t put the tool in starterpack, because you choose the tool. I don’t want to spawn right away with the tool.

That’s not gonna work with that code or turn out the way I want it.

Can you show with a screenshot where the tools are on the explorer?

Screenshot 2023-02-04 at 14.48.00

Does the player choose from a gui or?

They choose from clicking on the part that shows the weapon.

Then you should add a clickDetector on the part

There is. It’s just on another part.
Screenshot 2023-02-04 at 15.02.39

And here is the script for the clickdetector:

local function click2()
	game.Players.LocalPlayer.PlayerGui.Weapons:GetChildren().Value = false
	print("Clicked Rock")
	game.Workspace.Lobby.Show.Rock2.Transparency = 0.7
	game.Workspace.Lobby.Show.RockShow.Beep:Play()
	game.Workspace.Lobby.Show.Rock2.Color = Color3.new(0,255,0)
	game.Workspace.Lobby.Show.Rock2.Position = game.Workspace.Lobby.Show.RockShow.Position
	wait(0.1)
		game.Players.LocalPlayer.PlayerGui.Weapons.RockEquipped.Value = true
	wait(0.3)
	game.Workspace.Lobby.Show.Rock2.Transparency = 1
	game.Workspace.Lobby.Show.Rock2.Position = Vector3.new(game.Workspace.Lobby.Show.Rock2.Position.X,	game.Workspace.Lobby.Show.Rock2.Position.Y - 4, 	game.Workspace.Lobby.Show.Rock2.Position.Z) 
end
local clicked = false
game.Workspace.Lobby.Show.RockShow.ClickDetector.MouseClick:Connect(function()
	if not clicked then
		clicked = true
		click2()
		clicked = false
	end
end)

I dont get it, what do you need help in, whats not working upto your demand

local touched = false
function touch()
	local Player = game.Players.LocalPlayer
	if not Player.Character:FindFirstChildWhichIsA("Tool") then
		wait(1)
		print(Player)
		print(Player.PlayerGui)
		print(Player.PlayerGui.Weapons)
		print(Player.PlayerGui.Weapons.RockEquipped)
		print(Player.PlayerGui.Weapons.RockEquipped.Value)
		print(Player.PlayerGui.Weapons.RockEquipped.Value == true)
		if Player.PlayerGui.Weapons.RockEquipped.Value == true then
			game.Workspace.Lobby.Show.Rock.Handle.Anchored = false
			game.Workspace.Lobby.Show.Rock.Handle.Transparency = 0
			game.Workspace.Lobby.Show.Rock.Parent = Player.Backpack
		end 	
	end	
end	
game.Workspace.SpawnIn.Touch.Touched:Connect(function()
	if not touched then
		touched = true
		touch()
		wait(2)
		touched = false
	end		
end)

Line 4 is not working. I’m trying to make a system that stops you from getting multiple tools.

Is this localscript in workspace?

No, it’s in StarterGui. I know they can’t be there.

Is the tool not in the character? any errors in output?

Nope, no errors in the output.