Hello there. I am trying to make a difficulty chart obby and I am trying to make my own checkpoint system. I cannot figure out why on line 6 it outputs 'attempt to compare string and Instance'. Also, I need a little help moving a character to a checkpoint after they die. Here is my code.
script.Parent.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild('Humanoid') if h ~= nil then local chr = hit.Parent local plr = game.Players[chr.Name] if plr.leaderstats.Stage >= script.Parent.Name then else plr.leaderstats.Stage = script.Parent.Name end end end)
You are trying to compare the instance of the value, try doing Stage.Value
script.Parent.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild('Humanoid') if h ~= nil then local chr = hit.Parent local plr = game.Players[chr.Name] if tostring(plr.leaderstats.Stage.Value) >= script.Parent.Name then else tostring(plr.leaderstats.Stage.Value) = script.Parent.Name end end end)
The solution is this :
script.Parent.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild('Humanoid') if h ~= nil then local chr = hit.Parent local plr = game.Players[chr.Name] if plr.leaderstats.Stage.Value >= script.Parent.Name then else plr.leaderstats.Stage.Value = script.Parent.Name end end end)
You need to add a Value
in plr.leaderstats.Stage
because you're trying to compare the "value container" to the checkpoint number.
Let me explain :
Let's say you have a variable with a number inside, this will be a box with some balls containing the value inside of it.
With your script you're trying to compare the box with the CheckpointNumber, this will throw an error.
You need to do plr.leaderstats.Stage.Value
so that it will compare the number of balls inside the box (your variable) with the CheckPointNumber.
Hope this helped :)
Fixed it myself. Put a value along with the script inside the part. New script looks like this for anybody who wants to use it.
script.Parent.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild('Humanoid') if h ~= nil then local chr = hit.Parent local plr = game.Players[chr.Name] if plr.leaderstats.Stage.Value >= script.Parent.checkpointNumber.Value then else plr.leaderstats.Stage.Value = script.Parent.checkpointNumber.Value end end end)