Click to equip a vest

Ok so,
I’m trying to make a system where when the player click the vest model in the workspace, it destroys it and clone a vest acceosry stored in the Replicated storage in the player model. it also add health to the player. Problem is that depending on the team, the player will have more health than another (hammerDown = 175, DClass = 100), so I put 2 value in the player character which define if the player wear a Heavy Vest (Vest) or a Light Vest (LVest), for exemple, for HammerDown, Heavy vest value is set at true, so he can’t equip any other vest. Here is the code,

local plr = game.Players.LocalPlayer
local x = plr.Character.Vest.Value
local y = plr.Character.LVest.Value
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local click = script.Parent
local model = script.Parent.Parent
local vest = game.ReplicatedStorage.Vest


click.MouseClick:Connect(function()
	game.Players.PlayerAdded:Connect(function(player)
		if x == false and y == false and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			print("Destroyed")
			local v = vest:Clone()
			print("Clone")
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			print("equipped")
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 75
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 75
			print("Add health")
		elseif x == false and y == true and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			local v = vest:Clone()
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 25
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 25
		end
	end)
end)
1 Like

Sorry for the huge statement line, I didn’t know how to compress it

Why would you put a PlayerAdded function inside of a MouseClick function??

Oh s* didn’t realize, I made 2 different script, but for some reason, on my main world, output is flooded because of all the script. So I made a new baseplate and put script inside, so it easier to debug, I copied the main world script. sorry

Here is the seconde one :

local plr = game.Players.LocalPlayer
local x = plr.Character.Vest.Value
local y = plr.Character.LVest.Value
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local click = script.Parent
local model = script.Parent.Parent
local vest = game.ReplicatedStorage.Vest

game.Players.PlayerAdded:Connect(function(player)
	click.MouseClick:Connect(function()
		if x == false and y == false and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			print("Destroyed")
			local v = vest:Clone()
			print("Clone")
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			print("equipped")
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 75
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 75
			print("Add health")
		elseif x == false and y == true and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			local v = vest:Clone()
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 25
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 25
		end
	end)
end)

You don’t need the PlayerAdded function, you can just use a parameter to check the player who clicked.

click.MouseClick:Connect(function(player)

end)

I used a player added function to add the player team condition

But you don’t need it just use the parameter.

So how can I put a player.TEam condition?

click.MouseClick:Connect(function(player)
    if player.Team == Teams[""] or player.Teams == Teams[""] then
end)

Ok, imma try and I respond to this message

It doesn’t work, and the output doesn’t show any message

Can I see your code now? Also sorry for being late i was in class hhhhh

Ahah no problem I understand ^^
Here is the whole code :

local plr = game.Players.LocalPlayer
local x = plr.Character.Vest.Value
local y = plr.Character.LVest.Value
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local click = script.Parent
local model = script.Parent.Parent
local vest = game.ReplicatedStorage.Vest

click.MouseClick:Connect(function(player)
	if x == false and y == false and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			print("Destroyed")
			local v = vest:Clone()
			print("Clone")
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			print("equipped")
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 75
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 75
		print("Add health")
	elseif x == false and y == true and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			local v = vest:Clone()
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 25
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 25
		end
	end)

Is that a local script? LocalPlayer can not be used in a normal script. Also the script needs to be normal for the MouseClick to work. (You can add the x and y variables inside of the function)

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local click = script.Parent
local model = script.Parent.Parent
local vest = game.ReplicatedStorage.Vest

click.MouseClick:Connect(function(player)
local x = player.Character.Vest.Value
local y = player.Character.LVest.Value

	if x == false and y == false and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			print("Destroyed")
			local v = vest:Clone()
			print("Clone")
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			print("equipped")
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 75
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 75
		print("Add health")
	elseif x == false and y == true and player.Team == Teams["DClass"] or player.Team == Teams["Scientist"] or player.Team == Teams["Guard"] or player.Team == Teams["GRUP"] or player.Team == Teams["ChaosI"] or player.Team == Teams["GOC"] or player.Team == Teams["O5"] or player.Team == Teams["UIU"] then
			model:Destroy()
			local v = vest:Clone()
			v.Parent = plr.Character
			v.Name = "HeavyVest"
			x = true
			plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + 25
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 25
		end
	end)

It is a script sotred in server storage, so only one people can take the vest

scripts don’t run in server storage

I mean server script service sorry

1 Like

Sometimes I say idiot things…

But make sure to remove LocalPlayer, because it cant be used in a normal script.

1 Like