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.
01 | script.Parent.Touched:Connect( function (hit) |
02 | local h = hit.Parent:FindFirstChild( 'Humanoid' ) |
03 | if h ~ = nil then |
04 | local chr = hit.Parent |
05 | local plr = game.Players [ chr.Name ] |
06 | if plr.leaderstats.Stage > = script.Parent.Name then |
07 | else |
08 | plr.leaderstats.Stage = script.Parent.Name |
09 | end |
10 | end |
11 | end ) |
You are trying to compare the instance of the value, try doing Stage.Value
01 | script.Parent.Touched:Connect( function (hit) |
02 | local h = hit.Parent:FindFirstChild( 'Humanoid' ) |
03 | if h ~ = nil then |
04 | local chr = hit.Parent |
05 | local plr = game.Players [ chr.Name ] |
06 | if tostring (plr.leaderstats.Stage.Value) > = script.Parent.Name then |
07 | else |
08 | tostring (plr.leaderstats.Stage.Value) = script.Parent.Name |
09 | end |
10 | end |
11 | end ) |
The solution is this :
01 | script.Parent.Touched:Connect( function (hit) |
02 | local h = hit.Parent:FindFirstChild( 'Humanoid' ) |
03 | if h ~ = nil then |
04 | local chr = hit.Parent |
05 | local plr = game.Players [ chr.Name ] |
06 | if plr.leaderstats.Stage.Value > = script.Parent.Name then |
07 | else |
08 | plr.leaderstats.Stage.Value = script.Parent.Name |
09 | end |
10 | end |
11 | 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.
01 | script.Parent.Touched:Connect( function (hit) |
02 | local h = hit.Parent:FindFirstChild( 'Humanoid' ) |
03 | if h ~ = nil then |
04 | local chr = hit.Parent |
05 | local plr = game.Players [ chr.Name ] |
06 | if plr.leaderstats.Stage.Value > = script.Parent.checkpointNumber.Value then |
07 | else |
08 | plr.leaderstats.Stage.Value = script.Parent.checkpointNumber.Value |
09 | end |
10 | end |
11 | end ) |