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

Is there a way to sense if a gui is clicked in a global script rather than a local one?

Hi, I have this script,

script.Parent.MouseButton1Click:Connect(function()
	character = game.Players.LocalPlayer.Character
	player = game.Players:GetPlayerFromCharacter(character)

	player.Character.Humanoid.JumpPower = 75
	player.Character.Humanoid.WalkSpeed = 40
	player.Character.Humanoid.SpawnTime.Value = 5
	
	player.Backpack:ClearAllChildren()
	for _, _ in pairs (player.Character:GetChildren()) do if _.ClassName == ("Tool") then _:Destroy() end end
	game.ReplicatedStorage.Weapons.Ace["Commercia0l Airliner"]:Clone().Parent = player.Character


	wait(0.1)
	script.Parent.Parent:Destroy()
end)

It's located in a local script, and I was wondering if there was a way to make a global counterpart.

The issue I'm having is that since the new version is in a global script, will all players see the effect?

Additionally, I can't seem to figure out a global alternative for "game.Players.LocalPlayer", which, in the script is what determines who clicked the gui and applies the effect to only them.

6 comments

0

Im not sure about the main question, but if you put "player" in the parentheses in line 1 then it should give you the player.

0

I'm having trouble making this script that usually resides in a local script to work in a global script. Additionally, I don't see any mention of 'player' in line 1, did you mean line 2?

0

So you want the code to be run for all player in the server?

0

Not exactly, I was wondering if it's possible for a global script to perform the same as this local script, as in a player presses a gui and only that player receives the effects.

0

What is wrong with getting the player from the LocalPlayer function?

0

Nothings wrong with that method. I'm simply asking if there is a way to accomplish this script in a global script rather than a local one.

1 answer

Sort of: use RemoteEvents. Here's the manual.

In this case, the local script would be the one to listen for the gui to be clicked and then fire a RemoteEvent that a server script is listening to. The server could then be responsible for lines 5-11. The server need only apply those lines to the player who activated the gui (as the first argument in the OnServerEvent is the player who activated the event -- in this case, the player who clicked the gui).

Also, replace lines 2-3 with local player = game.Players.LocalPlayer (you don't need to use GetPlayerFromCharacter when you just want the LocalPlayer -- that function is for the case .that you have a reference to the character model and need the player it belongs to)

2 comments

0

Hmm, not quite. I'm asking for assistance on turning this LOCAL script into a GLOBAL script.

0

What do you mean by "global" script, if not a server script?

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