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

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

Asked by 6 years ago

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.

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. SchonATL 15 — 6y
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? jiggiypuffs 30 — 6y
0
So you want the code to be run for all player in the server? textartotoboy2 5 — 6y
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. jiggiypuffs 30 — 6y
View all comments (2 more)
0
What is wrong with getting the player from the LocalPlayer function? marsupicide 60 — 6y
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. jiggiypuffs 30 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)

0
Hmm, not quite. I'm asking for assistance on turning this LOCAL script into a GLOBAL script. jiggiypuffs 30 — 6y
0
What do you mean by "global" script, if not a server script? chess123mate 5873 — 6y
Ad

Answer this question