Hmm, wack. Then, instead of moving the parent of the map, go back to cloning it, but place a script to handle the ClickDetector and parent it to all of them. This should work:
script.Parent.MouseClick:Connect(function(plr)
-- add the points
end
Hmm, wack. Then, instead of moving the parent of the map, go back to cloning it, but place a script to handle the ClickDetector and parent it to all of them. This should work:
script.Parent.MouseClick:Connect(function(plr)
-- add the points
end
I did that before and it didnât work but ill try that again
Nope still donât get any points and still no errors. I do have an error at the beginning of the test that says âloadstring is not availbleâ but im pretty sure it doesnât have anything to do with it.
Hmm. Add a print statement in the function and check again. Does it print?
No it does not print. Here is the script in the clickdetector:
script.Parent.MouseClick:Connect(function(player)
local leaderstats = player.leaderstats
local points = leaderstats.Points
points.Value = points.Value + 10
print("won")
end)
Here is the points system. I dont see any problem maybe you will.
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)
Try putting a print statement at the very beginning to check whether or not the script runs at all, because I donât see a problem with it.
Still does not print anything.
does the output show any errors?
No it does not except when i start the test i shows " loadstring is anavailble"
where do you have a loadsting in your script?
Im new at proggraming so iâm not really sure what is loadstring
ooh ok
Where is the script located again?
For the points its in the clickdetector. The points system is in the serverscriptsservice
Scripts wonât run if theyâre descendants of ReplicatedStorage, but they should as soon as theyâre moved to Workspace, so Iâm not sure.
I think i found the solution. The problem was that when i pressed the button it parented the map to the replicated storage before I got the chance to get the points so I added a wait(1) for the tp back to replicatedstorage and it worked! but also now the player can press multiple times on the button and he will get more points then needed
How do I make so the clickdetector can not be pressed again for a couple of seconds after it been pressed once?
Glad to see you figured it out!
To prevent that from happening, you can use a debounce. Hereâs an example:
local debounce = false
local cooldown = 10
button.MouseClick:Connect(function()
if debounce == true then return end
debounce = true
-- do stuff
wait(cooldown)
debounce = false
end)
The first time this function runs, it sets debounce to true, does its normal stuff, and sets debounce back to false after it finishes. If the function runs again, then the function will return early without doing anything because it hasnât finished running the first time.
Isnât it shoud be
â do stuff
debounce = false
wait(cooldown)
debounce = true ?
Sure, that would work too, assuming that the âdo stuffâ part doesnât wait or take too long to run.