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

How can I make a tool giver GUI like a trolling GUI?

Asked by 4 years ago

So, I have a gui that has a textbox, and when a players name is put onto the textbox and a button is clicked they receive a specific item, any idea on how I can do this?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can do this with FindFirstChild(). Basically if we use FindFirstChild() then add the TextBox.Text into the "()" we are trying to Find the Child that has a name of the TextBox's Text.

First add a RemoteEvent into ReplicatedStorage, we will be firing this from the Local Script to then give the player the item.

Then add a Local Script to your Button.

Next add a Server Script into ServerScriptService.

Then add the following code: (You will probably need to change these locations inside the scripts to wherever your stuff is located.)

Local Script:

local Players = game.Players
local Player = game.Players.LocalPlayer
local Button = script.Parent
local RemoteEvent = game.ReplicatedStorage.RemoteEvent


Button.MouseButton1Click:Connect(function()

    local TextBox = Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TextBox")

    local FoundPlayer = Players:FindFirstChild(TextBox.Text)

    if FoundPlayer then
            RemoteEvent:FireServer(FoundPlayer, Button.Name)
    end
end)

Server Script:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player, FoundPlayer, ButtonName)

    if ButtonName == "Name" then
        local Item = game.ReplicatedStorage.Item
        Item:Clone().Parent = FoundPlayer:FindFirstChild("Backpack")
    elseif ButtonName == "OtherName" then
        local Item = game.ReplicatedStorage.OtherItem
        Item:Clone().Parent = FoundPlayer:FindFirstChild("Backpack")


end)
0
Hey so, my texbox and all that are in a Frame, any modifications I need to do? airsoft561 -3 — 4y
0
You'll just need to change the variable locations. So if the Textbox and the Button are in the same frame then you'll need to change both their Variables in the local script and just add a :WaitForChild("Frame") then the button, textbox, etc. xInfinityBear 1777 — 4y
0
Should look like this: Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextButton") -- Do the same with the TextBox. Also change ScreenGui to your ScreenGui's Name. xInfinityBear 1777 — 4y
0
I suppose they all don't need to be :WaitForChild() but I do it just in case. As for the server script, you'll just need to change the variable location to where the item is you want to give the player. xInfinityBear 1777 — 4y
View all comments (42 more)
0
If you get any errors just let me know. I'll help you solve it. xInfinityBear 1777 — 4y
0
Also, there are multiple buttons. airsoft561 -3 — 4y
0
Multiple Buttons? xInfinityBear 1777 — 4y
0
Yes, multiple buttons, one gives a sword, another gives a gun etc. airsoft561 -3 — 4y
0
Ah okay. xInfinityBear 1777 — 4y
0
I mean, you could add a Folder into ReplicatedStorage holding all your RemoteEvents and call them "GiveSword", "GiveGun", etc. and do the same thing with the Server Scripts, and name the Scripts the same, then just change the item you want to give the player. xInfinityBear 1777 — 4y
0
Oh, so a script for each item? airsoft561 -3 — 4y
0
You'll also want to add a local script to each Button aswell, then change the RemoteEvent variable to the RemoteEvent to want to fire, so if the button you want to click on is going to give the player a sword, get the RemoteEvent called "GiveSword" or whatever you named it. xInfinityBear 1777 — 4y
0
Yeah a script for each item. There might be a better way though, I'll look into it. xInfinityBear 1777 — 4y
0
Okay, nevermind I've found a better way. I'll edit my code above. Basically you can check if the ButtonName is equal to "Item". xInfinityBear 1777 — 4y
0
Edited the code. xInfinityBear 1777 — 4y
0
I have 3 buttons, so do I do elseif for the other one? airsoft561 -3 — 4y
0
Yes xInfinityBear 1777 — 4y
0
Also just note that if you're going to put the actual Item name in the speech marks then the ButtonName has to be that name, otherwise it wont work, I guess it doesn't have to be the item name, you could also say, if ButtonName == "GiveItemSwordButton" or whatever your Button names are then it will still give the player that item. xInfinityBear 1777 — 4y
0
You just gotta make sure that the ButtonName is indeed equal to what you're putting in the speech marks. xInfinityBear 1777 — 4y
0
Hey so how can I make the event give the item airsoft561 -3 — 4y
0
It's in the Server Script. Where the "local item" is, change the location to where the Item is, is it inside a folder inside ReplicatedStorage, ServerStorage? If it's in ReplicatedStorage then do local item = game.ReplicatedStorage.Items.Item -- Items is the folder that the Item is stored in, change "Item" to item you want to clone. xInfinityBear 1777 — 4y
0
Then we are cloning it into the Player's Backpack. xInfinityBear 1777 — 4y
0
If you also want the Player to still have that item when they reset their character, clone it into their StarterGear aswell. xInfinityBear 1777 — 4y
0
I get an error in the output saying : " ServerScriptService.Script:3: attempt to call a userdata value" airsoft561 -3 — 4y
0
Could you edit your question and add the code or put it on pastebin and send me the link so I can view your code? xInfinityBear 1777 — 4y
0
Okay.. xInfinityBear 1777 — 4y
0
Try this: https://hastebin.com/corizagoke.bash I've edited the code and made the variables to what you had. Let me know if it doesn't work. xInfinityBear 1777 — 4y
0
I messed up a bit of the code, I've updated the link. xInfinityBear 1777 — 4y
0
hey so uhm i was making the local script for each one and i dont know which remote event to use, do i just put all the tools in 1 remote event? airsoft561 -3 — 4y
0
The Tools don't have to be in the RemoteEvent. You only need 1 RemoteEvent for this to work, put the RemoteEvent into ReplicatedStorage and if you want to put the Tools into it you can, but I wouldn't do this, I'd add a folder into ReplicatedStorage and name it Items and add the Tools into it. xInfinityBear 1777 — 4y
0
and how would I need to modify the code? airsoft561 -3 — 4y
0
All you need to do is change the item variable in the Server Script, if you've created a Folder into ReplicatedStorage and named it "Items" and put the Tools into it then you can just copy this: https://hastebin.com/ejejazaxuw.bash xInfinityBear 1777 — 4y
0
My bad, I forgot to change the RemoteEvent Variable in the Server Script. https://hastebin.com/xiwehuzawe.bash xInfinityBear 1777 — 4y
0
Let me know if it works or not xInfinityBear 1777 — 4y
0
I doesn't work, I get this error in the output: " RemoteEvent is not a valid member of ReplicatedStorage" I put the tools in a folder named Items in replicatedstorage airsoft561 -3 — 4y
0
Where is your RemoteEvent located? xInfinityBear 1777 — 4y
0
i dont have one, in the one you gave me there is still a remote event. airsoft561 -3 — 4y
0
You need to add a RemoteEvent into ReplicatedStorage. Add a RemoteEvent into ReplicatedStorage and then see if it works. xInfinityBear 1777 — 4y
0
where should the remove event be? like a parent of the Items folder or an Item? airsoft561 -3 — 4y
0
It should be inside of ReplicatedStorage, it's Parent needs to be ReplicatedStorage xInfinityBear 1777 — 4y
0
"MouseButton1Click is not a valid member of Frame" thats the error i get, the local script is just in the frame. airsoft561 -3 — 4y
0
The local script needs to be in the buttons, each button should have the local script. xInfinityBear 1777 — 4y
0
Your explorer should look something like this: https://gyazo.com/48a5d0f563a9c92054289ae10830c82e xInfinityBear 1777 — 4y
0
Let me know if it works or not. xInfinityBear 1777 — 4y
0
Thank you alot, it works. airsoft561 -3 — 4y
Ad

Answer this question