Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

i made some scripts where u clik a cookie and i gives you a point but i does not work why?

this is my events script

 >   script.AddPoints.OnServerEvent:Connect(function(plr)
	plr.leaderstats.points.Value = plr.leaderstats.points.Value +1
end)

and here is my localscript

  script.Parent.MouseClick:Connect(function()
	workspace.Cookie.ClickDetector.event.AddPoints:FireServer()
end)

and here is my leaderstats

game.Players.PlayerAdded:Connect(function(plr)
	local leader = Instance.new("Model")
	leader.Name = "leaderstats"
	leader.Parent = plr
	local points = Instance.new("IntValue")
	points.Name = "points"
	points.Parent = leader
	points.Value = 0
end)

plz help thx -Amin

1 comment

0

Any errors?

2 answers

I think to solve that you need to start through a Serverscript, which would detect the click. I think you don't really need a remoteEvent, as a serverscript can get the player through a clickDetector. So try to put this:

local clickDetector = script.Parent

function onClicked(player)
	print("Player got a cookie!")
	player.leaderstats:WaitForChild("points").Value = player.leaderstats:WaitForChild("points").Value + 1
end

clickDetector.MouseClick:Connect(onClicked)

Hope it helps!

The problem is that the ClickDetector MouseClick event isn't for the client, but for the server. Putting it in a local script won't work for this, instead, try this:

--Server Script Only
script.Parent.MouseClick:Connect(function(player) --You receive a player parameter with the MouseClick event.
	local leaderstats = player:WaitForChild("leaderstats")
	local point = leaderstats:FindFirstChild("points")
	point.Value = point.Value + 1
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.