fval = game.Players.LocalPlayer.PlayerGui.Values.Flag.Value function touch() fval = 1 print("hi") end script.Parent.BFlagCanister:connect(touch)
In a local script and there is no output message.
Values
is the thing holding all the other values.
Flag
is an intvalue
.
BFlagCanister
is the block. It is anchored, has a mesh, is no collided .
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) --This is an anonymous function. We're going to write a function in the brackets and close it off at the end. local player=game.Players:GetPlayerFromCharacter(hit.Parent) local fval=player.PlayerGui.Values.Flag.Value fval=1 print("hi") end) --Note that the parenthesis/bracket is closed at the end of the function so that it's incorporated into the event's connection properly.
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.
You're missing a Touched
at the end of your script, I believe that is your Problem,
function touch(hit)--Catches whoever touches it local player=game.Players:GetPlayerFromCharacter(hit.Parent) --the GetPlayerFromCharacter is pretty useful in cases, like this local fval=player.PlayerGui.Values.Flag.Value fval=1 print("hi") end script.Parent.Touched:connect(touch)
You can learn more about functions/events at ROBLOX Wiki
You messed up on your connecting part.
fval = game.Players.LocalPlayer.PlayerGui.Values.Flag.Value function touch() fval = 1 print("hi") end script.Parent.Touched:connect(touch)
I believe your problem is at line 4. You are not allowed to hold a property in a variable.