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)
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
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)
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)