PLEASE READ THIS BEFORE COPYING CODE!
If you hover over a local script when inserting something into an object it'll read that it can only run under certain conditions, such as if it's inside of a character model, inside of a GUI, inside of the ReplicatedFirst service, etc. It didn't work since it didn't fulfill any of the conditions above, therefore not running.
So how do we fix this? Here's how;
(I'm assuming you want local parts. If you don't want that then use RemoteEvents.)
local Player = game:GetService("Players").LocalPlayer
local Part = workspace.Part
local Coins = Player.leaderstats.Coins
function onChanged()
if Coins.Value >= 2 then
Part.Transparency = 1
end
end
Coins:GetPropertyChangedSignal("Value"):Connect(onChanged)
In the code above we define the player, part, and coins in separate variables. We also have a function that fires every time value of Coins changes. we check if the value is 2 and if that's the case we change the part's transparency property to 1. The code above should be placed as a local script inside of the StarterPlayerScripts.
We do this on purpose so the part's transparency doesn't replicate to other players.
Edit: Another problem is that the conditional statement only runs once not to mention the conditional also doesn't run if the value of "Coins" the greater than 2. Fixed!
4 comments
is there any infinite yield in the output? and is the code in a localscript?
You can't use a localscript inside a part. Instead- move the script to ScreenGui.
yes, but i want it to effect a a part, not a gui. :/
also i tried making it effect the brick through game.workspace, still didnt work in a gui.