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

From "Touched:Connect(function(hit)" to GUI click?

Asked by 5 years ago

Im editing an script that works for a touch brick function

script.Parent.Union.Enter.Touched:Connect(function(hit)
    wait()
    local plr = nil
    if (GlobalCooldown) then return end
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        Open(plr)
        GlobalCooldown = true
        wait(GlobalCooldownAmt)
        GlobalCooldown = false
        repeat wait(0.1) until plr:DistanceFromCharacter(script.Parent.Union.Position) > 15
    end
end)

But i want it to work if you click a gui button, im doing this but dont work, please help

script.Parent.MouseButton1Up:Connect(function(clic)
    wait()
    local plr = nil
    if (GlobalCooldown) then return end
    if game.Players:GetPlayerFromCharacter(clic.Parent) then
        plr = game.Players:GetPlayerFromCharacter(clic.Parent)
        Open(plr)
        GlobalCooldown = true
        wait(GlobalCooldownAmt)
        GlobalCooldown = false
        repeat wait(0.1) until plr:DistanceFromCharacter(clic.Parent)
    end
end)

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

Unlike .Touched, .MouseButton1Click does not give you any arguments. As guis can only be manipulated through LocalScripts, you should be able to just get the LocalPlayer itself. LocalScripts only execute inside of something that is individual to each player, such as a gui, so the LocalScript should be inside your gui button (which it looks like it is), and then you can do something like this:

script.Parent.MouseButton1Up:Connect(function()
    local plr = game.Players.LocalPlayer
    --do stuff
end)

Each player has their own set of guis, so the LocalPlayer will be the player that owns the gui that was clicked (aka the player who clicked the gui).

Hope this helps!

0
I changed what u said and still not working DJBrianL 0 — 5y
0
Any errors? If not, try adding prints at each step and see where it goes wrong. mattscy 3725 — 5y
0
Nvm, I was doing something bad, thank you very much for the help, now it worked DJBrianL 0 — 5y
Ad

Answer this question