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)
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!