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)

2 comments
I converted it to a script, and now I get this error. How would I fix it? Workspace.Part.Script:8: attempt to index upvalue 'player' (a nil value)
Ah, you'd need to remove player from line 3. Then, write, 'local player = game.Players:GetPlayerFromCharacter(hit.Parent)' on line 6 (right after the start of the function), then say 'if (humanoid ~= nil) and (player) then' instead of just 'if (humanoid ~= nil) then'.