Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click for points script will not work, no errors?

Asked by 2 years ago

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
0
i don't see anywhere in the script that would give them points theking66hayday 841 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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)

Ad

Answer this question