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

Click for points script will not work, no errors?

So i want to detect when the player clicks so i can give them points though my script wont work, it shows no errors or anything, it is a local script inside of the GUI


local ReplicatedStorage = game:GetService("ReplicatedStorage")

while true do
	wait(0.01)
	if ReplicatedStorage.PlayerLoaded == true then
		print("load successful for "..game.Players.LocalPlayer.Name)
		script.Parent.Frame.Visible = true
		
		local Cooldown = false
		
		local Mouse = game.Players.LocalPlayer:GetMouse()
		Mouse.Button1Down:Connect(function()
			if Cooldown == false then
				ReplicatedStorage.ClickEvent:FireServer()
				Cooldown = true
				wait(0.1)
				Cooldown = false
			end
		end)
	end
end


1 comment

0

i don't see anywhere in the script that would give them points

1 answer

✓ Accepted answer

I wouldn't recommend listening to Mouse.Button1Down in a while true loop. I would do something like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- repeating the wait() function until PlayerLoaded is true, aka yielding
repeat wait() until ReplicatedStorage.PlayerLoaded.Value == true

print("load successful for "..game.Players.LocalPlayer.Name)
script.Parent.Frame.Visible = true

local Cooldown = false

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(function()
    print("mouse click")
    if Cooldown == false then
        print("cooldown disabled")
        ReplicatedStorage.ClickEvent:FireServer()
        Cooldown = true
        wait(0.1)
        Cooldown = false
    end
end)

I've added two more prints for debugging (lines 12 and 14)

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