Hi, I'm new to scripting ROBLOX LUA but I am already fluent in languages like C, C++, Java, and Python. I was wondering why this script won't work. I have a leader board setup and want to make this part change color when touched if you have enough points. I get no errors or even warnings but It won't do anything. Here is the localscript which is inside of the Part that I want to change color:
01 | local OJ = game:GetService( "ReplicatedStorage" ).OJ |
02 | OJ.Archivable = true |
03 | local player = game.Players.LocalPlayer |
04 | local buyOJ = script.Parent |
05 |
06 | local function touchedOJ(hit) |
07 | local priceOJ = game.Workspace.Prices.ojPrice |
08 | local playerPoints = player.leaderstats.Points.Value |
09 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
10 | if (humanoid = = nil ) then |
11 | if (playerPoints > = priceOJ) then |
12 | buyOJ.BrickColor = BrickColor.new( "Lime green" ) |
13 | else |
14 | buyOJ.BrickColor = BrickColor.new( "Really blue" ) |
15 | print ( "Not enough points!" ) |
16 | end |
17 | end |
18 | end |
19 |
20 | buyOJ.Touched:Connect(touchedOJ) |
WarmFireBlaz1 You are Very wrong for being 2 hours ago. Here you go!
01 | local OJ = game:GetService( "ReplicatedStorage" ).OJ |
02 | OJ.Archivable = true |
03 | local player = game.Players.LocalPlayer |
04 | local buyOJ = script.Parent |
05 |
06 | local function touchedOJ(hit) |
07 | local priceOJ = game.Workspace.Prices.ojPrice.Value --You have not added .Value at the end |
08 | local playerPoints = player.leaderstats.Points.Value |
09 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
10 | if (humanoid = = nil ) then |
11 | if (playerPoints > = priceOJ) then |
12 | buyOJ.BrickColor = BrickColor.new( "Lime green" ) |
13 | else |
14 | buyOJ.BrickColor = BrickColor.new( "Really blue" ) |
15 | print ( "Not enough points!" ) |
16 | end |
17 | end |
18 | end |
19 |
20 | buyOJ.Touched:Connect(touchedOJ) |
So, you're making the two common mistakes of beginner scripting (we all have).
01 | local OJ = game:GetService( "ReplicatedStorage" ).OJ |
02 | OJ.Archivable = true |
03 | local player = game.Players.LocalPlayer |
04 | local buyOJ = script.Parent |
05 |
06 | local function touchedOJ(hit) |
07 | local priceOJ = game.Workspace.Prices.ojPrice |
08 | local playerPoints = player.leaderstats.Points.Value |
09 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
10 | if (humanoid ~ = nil ) then -- I don't know how no one noticed this, but in your original script, you checked if the humanoid **WAS** nil. Here you're checking if it **IS NOT** nil. |
11 | if (playerPoints > = priceOJ) then |
12 | buyOJ.BrickColor = BrickColor.new( "Lime green" ) |
13 | else |
14 | buyOJ.BrickColor = BrickColor.new( "Really blue" ) |
15 | print ( "Not enough points!" ) |
16 | end |
17 | end |
18 | end |
19 |
20 | buyOJ.Touched:Connect(touchedOJ) |
Only Scripts work in Parts. Consider turning the localscript into a regular script. Many coders new to LUA often make this mistake... like I did.