Points system doesn't work

So should i put the new script in this script:

local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points =  Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
1 Like

i have used this before, no errors on anything, its the same thing as value = value + 1, it doesnt have to be professional, it just has to work

1 Like

No, I was referring to this one. Instead of using Event.OnServerEvent, you can use Part.ClickDetector.MouseClick.

1 Like

I tried that before in it didn’t work and thats why i changed it to event.onseverevent but i will try that again now.

1 Like

Try using print to mark when the function runs to make sure the event is being received properly.

1 Like

@idan1973
What is it exactly you’re trying to do? (Sorry if i look stupid)

1 Like

I am trying to make an event that when a player presses the button he gets 10 points.

1 Like
script.Parent.ClickDetector.MouseClick:Connect(function(p)
p:WaitForChild("leaderstats"):FindFirstChild("Points") += 10
end)

Sorry for the WaitForChild and FindFirstChild, sometimes you get errors due to the script not being able to find it

1 Like

Made a new script still doesn’t work. Here it is :

local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points =  Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(onPlayerJoin)


local buttonbluemap1 = game.ReplicatedStorage.Obbys.Obby1.ButtonBlue.Button.ClickDetector
local buttonredmap1 = game.ReplicatedStorage.Obbys.Obby1.ButtonRed.Button.ClickDetector
local buttonbluemap2 = game.ReplicatedStorage.Obbys.Obby2.ButtonBlue.Button.ClickDetector
local buttonredmap2 = game.ReplicatedStorage.Obbys.Obby2.ButtonRed.Button.ClickDetector

local function buttonpressed(player)
	local leaderstats = player.leaderstats
	local points = leaderstats.Points
	points.Value = points.Value + 10
end


buttonbluemap1.MouseClick:Connect(buttonpressed)
buttonredmap1.MouseClick:Connect(buttonpressed)
buttonbluemap2.MouseClick:Connect(buttonpressed)
buttonredmap2.MouseClick:Connect(buttonpressed)

This Might work.

for  _,Buttons in pairs(game.ReplicatedStorage.Obbys.Obby1:GetChildren()) do
if string.match(Buttons.Name, "Button") then
for _, CD in pairs(Buttons:GetChildren()) do
if CD:IsA("ClickDetector") then
CD.MouseClick:Connect(buttonpressed)
end
end

Isn’t it the same function just written different?

no, its a for loop that finds all buttons that has the word “Button”, then it looks for a ClickDetector, it executes it for all of the buttons instead of one of them

Your parts and clickdetectors are ancestors of ReplicatedStorage, and can’t be physically interacted with. Are they moved out at any point?

1 Like

Yeah when the round begins two players are being teleported to the map an also the map changes randomly. Right now i have two different test maps, one of them will be teleport to the workspace and so also the two buttons of the map

1 Like

Does the script that begins the game use the Clone() function to clone the button?

1 Like

Yes it does. It’s in the round system the main script.

That is why it does not work, you are only connecting the function to the ones in ReplicatedStorage.

Try parenting the increment script to the clickdetector or reparenting the entire test map instead of cloning it. If that doesn’t fix the issie, it may be something else.

1 Like

Ok ill try that in a couple of minutes.

I changed the script so the test map it’s self will change parent to workspace and back to replicated storage but i get this error “The Parent property of Obby1 is locked, current parent: NULL, new parent ReplicatedStorage” and also i have infinte yield possible for

workspace:WaitForChild(buttonredmap1).MouseClick:Connect(buttonpressed)
workspace:WaitForChild(buttonbluemap1).MouseClick:Connect(buttonpressed)
workspace:WaitForChild(buttonredmap2).MouseClick:Connect(buttonpressed)
workspace:WaitForChild(buttonbluemap2).MouseClick:Connect(buttonpressed)