I have typed a code that gives you points when you touch it with help from peasfactory
enabled = false script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil and enabled == false then enabled = true script.Parent.BrickColor = BrickColor.new("Really red") local player = game.Players:GetPlayerFromCharacter(hit.Parent) local points = player.leaderstats.Points points.Value = points.Value + 5 wait(3) enabled = false script.Parent.BrickColor = BrickColor.new("Sea green") end end)
But When I try to change it to a click detector it doesn't work and tells me the player is nil
enabled = false script.Parent.ClickDetector.MouseClick:Connect(function(click) local humanoid = click:FindFirstChild("Humanoid") if humanoid ~= nil and enabled == false then script.Parent.BrickColor = BrickColor.new("Really red") enabled = true local player = game.Players:GetPlayerFromCharacter(click) local points = player.leaderstats.Points points.Value = points.Value + 5 wait(3) enabled = false script.Parent.BrickColor = BrickColor.new("Sea green") end end)
Okay, I see what you've tried to done here and you almost did it.
You see, ClickDetector always gives the player variable.
Example:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
There is no need to use GetPlayerFromCharacter since it automatically gives you the character.
Your script should look like this:
local enabled = false script.Parent.ClickDetector.MouseClick:Connect(function(player) if enabled == false then script.Parent.BrickColor = BrickColor.new('Really red') enabled = true local points = player.leaderstats.Points points.Value = points.Value + 5 wait(3) enabled = false script.Parent.BrickColor = BrickColor.new('Sea green') end end)