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:
local OJ = game:GetService("ReplicatedStorage").OJ OJ.Archivable = true local player = game.Players.LocalPlayer local buyOJ = script.Parent local function touchedOJ(hit) local priceOJ = game.Workspace.Prices.ojPrice local playerPoints = player.leaderstats.Points.Value local humanoid = hit.Parent:FindFirstChild("Humanoid") if(humanoid == nil) then if(playerPoints >= priceOJ) then buyOJ.BrickColor = BrickColor.new("Lime green") else buyOJ.BrickColor = BrickColor.new("Really blue") print("Not enough points!") end end end buyOJ.Touched:Connect(touchedOJ)
WarmFireBlaz1 You are Very wrong for being 2 hours ago. Here you go!
local OJ = game:GetService("ReplicatedStorage").OJ OJ.Archivable = true local player = game.Players.LocalPlayer local buyOJ = script.Parent local function touchedOJ(hit) local priceOJ = game.Workspace.Prices.ojPrice.Value --You have not added .Value at the end local playerPoints = player.leaderstats.Points.Value local humanoid = hit.Parent:FindFirstChild("Humanoid") if(humanoid == nil) then if(playerPoints >= priceOJ) then buyOJ.BrickColor = BrickColor.new("Lime green") else buyOJ.BrickColor = BrickColor.new("Really blue") print("Not enough points!") end end end buyOJ.Touched:Connect(touchedOJ)
So, you're making the two common mistakes of beginner scripting (we all have).
local OJ = game:GetService("ReplicatedStorage").OJ OJ.Archivable = true local player = game.Players.LocalPlayer local buyOJ = script.Parent local function touchedOJ(hit) local priceOJ = game.Workspace.Prices.ojPrice local playerPoints = player.leaderstats.Points.Value local humanoid = hit.Parent:FindFirstChild("Humanoid") 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. if(playerPoints >= priceOJ) then buyOJ.BrickColor = BrickColor.new("Lime green") else buyOJ.BrickColor = BrickColor.new("Really blue") print("Not enough points!") end end end 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.