I am trying to make a game with a simple attachment system, you can click on an item, and then click on a vehicle to put it on.
It simply does not activate one line of code no matter what, which is the line that clears the variable that says what item is equipped, but it does work for ONE test if I remove and re-add the script, which makes no sense. Every other line, before and after will activate, and when I print the state of the variable it says it has been cleared, even though it has not. There are either no errors, or the errors have nothing to do with the script.
I have tried putting it in a new script, separating it into multiple scripts, and just tweaking it in general.
wait(0.5)
function chng(player)
if player.leaderstats.Holding.Value == "None" and script.Parent.Value.Value ~= "" then
player.leaderstats.Holding.Value = script.Parent.Value.Value
script.Parent.Value.Value = ""
script.Parent.Equip:Play()
script.Parent:FindFirstChildOfClass("Model"):Remove()
player.leaderstats.MiscStat.Value = script.Parent.MiscStat.Value
script.Parent.MiscStat.Value = 0
elseif player.leaderstats.Holding.Value ~= "None" and script.Parent.Value.Value == "" then
script.Parent.Value.Value = player.leaderstats.Holding.Value
script.Parent.Equip:Play()
local e = game.ReplicatedStorage[player.leaderstats.Holding.Value]:Clone()
e.MiscStat.Value = player.leaderstats.MiscStat.Value
player.leaderstats.MiscStat.Value = 0
e.Parent = script.Parent
e:SetPrimaryPartCFrame(script.Parent.Part.CFrame)
player.leaderstats.Holding.Value = "None"
local a = Instance.new("WeldConstraint")
a.Parent = e
a.Part0 = e.PrimaryPart
a.Part1 = script.Parent.Part
end
end
script.Parent.ClickDetector.MouseClick:Connect(chng)
This is the code, tell me if there is anything wrong with it
There is no error, like I said in the post above.
Where is the code stored? Furthermore, are there any RemoteEvents and/or RemoteFunctions?