✓ Accepted answer
TheContinentofEurope is getting there, but there is a problem that I can spot in the script.
Shortening your script:
Before I get into what the error is, we're going to shorten the script. Shortening your scripts improves efficiency and is helpful when you have tons of scripts running at once.
You can use a function and then use an event to connect it, it works none the less. But, you can do this all in one go using an anonymous function.
script.Parent.Touched:connect(function(hit)
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
local fval=player.PlayerGui.Values.Flag.Value
fval=1
print("hi")
end)
The error itself:
The actual error in your script is that you're trying to do a "shortcut". If you set a variable as a value of a Value object, you'd think it would update if you did "fval=1". This is not the case, if you do this, the value won't update because the computer will handle that line as if you're setting the variable. If you printed fval after you did "fval=1" with your current script, it would print 1, but if you go to your value, the value won't have changed.
To fix this, we will do the following.
script.Parent.Touched:connect(function(hit)
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
local fval=player.PlayerGui.Values.Flag
fval.Value=1
print("hi")
end)
See how we're setting the value property on the next line instead of setting it as the variable? If we do it this way, it should work. Let me know if there's any problems and make sure to check your output window for errors in your script.
Good luck!
Learn more on anonymous functions here.
1 comment
Mind explaining BFlagCanister please.