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

How do i fix a tool you receive from a GUI?

Asked by 4 years ago

So i made a GUI text button with a script to receive a tool it works but it only works for the local script meaning other players cant see the tool except me... i did copy and paste my script to a Script not a local script but it did not work i did not get to receive the tool this is my script

local plr = game.Players.LocalPlayer
local tool = game.StarterGui.FlightAttendant.GiveCart.Cart

script.Parent.MouseButton1Click:Connect(function()
    tool:Clone().Parent = plr.Backpack
end)

please help me do i put in a module script as i don't really know what it means, is there even a fix to this?

1
you should probably abide by filtering enabled rules Fifkee 2017 — 4y
0
How? sorry to be that guy memesfordaysa 2 — 4y

1 answer

Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
4 years ago
Edited 4 years ago

Like someone said before, you will need to abide to the FilteringEnabled rules. Previously, your code would look perfectly fine but not anymore.

In order to get a tool that everyone can see, you need to use a Remote Event to establish a connection with the server.

You keep all client sided scripting in your GUI's script, so pretty much only connecting to the click. Afterwards, you want to fire the server, which will give you the tool.

I will give you a fairly simple example, which you might want to improve, in order to prevent exploiters to get the cart in their inventory.

-- Local script

-- where the RemoteEvent will be
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("CartEvent") -- the event

script.Parent.MouseButton1Click:Connect(function()
    event:FireServer()
end)

Now in the server's script:

-- server script
local replicatedStorage = game:GetService("ReplicatedStorage")

-- creating the event
local event = Instance.new("RemoteEvent")
event.Name = "CartEvent") -- name it whatever you would like
event.Parent = replicatedStorage

local tool = script.Parent.Cart -- wherever your tool is

-- Connecting to when players fire the event
event.OnServerEvent:Connect(function(player) 
    -- the first argument is always the player who fired the event

    -- finally, we give the player the tool
    tool:Clone().Parent = player.Backpack
end)

Like I mentioned before, you might want to improve this code by adding checks that prevent non-staff members to get the tool. You can do this by checking their rank in your group, and only give them the tool if they are indeed in a staff position.

Useful documentation: Remote Event, ReplicatedStorage, GetRankInGroup()

Ad

Answer this question