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

Why aren't you able to give someone a tool using a Screen Gui except for yourself?

Asked by
l1u2i3 52
5 years ago

So what I'm trying to do is make a type of machine that gives you tickets. What you would do is type your username or someone else's into a TextBox and click a TextButton to give the player that has the username which you inserted a ticket. The problem I'm having is that it won't work when you're trying to give the ticket to another player. Instead, it would only work when you would give the Ticket to yourself. I've already tried both Local and Regular scripts.

01-------Down below is the script that I used for giving the ticket to the player and getting its username.
02 
03    -------------------------------Getting Player's Name and Giving Ticket
04 
05    script.Parent.MouseButton1Click:Connect(function()
06        script.Parent.Parent.StringValue.Value = script.Parent.Parent.TextBox.Text
07 
08    -----Getting username inserted in the TextBox into a StringValue
09 
10 
11    wait()
12        local Name = script.Parent.Parent.PlayerName.Value
13                                    --- Getting the value from the StringValue
14        local TicketToGive = game.Players:WaitForChild(Name)
15                                    --- Finding Player
16    local Clone = game.ReplicatedStorage.Ticket:Clone()
17                                    ---Cloning the Ticket from Replicated Storage
18        Clone.Parent = TicketToGive.Backpack
19                                    ---Giving the Cloned Ticket to the Player.
20    end)
0
did you look into remote events? Fad99 286 — 5y

1 answer

Log in to vote
1
Answered by
cegberry 432 Moderation Voter
5 years ago
Edited 5 years ago

Cloning stuff from ReplicatedStorage with a LocalScript, and trying to give it to another person won't show up for them, as its FE, meaning anything a localscript changes, it won't distribute to other client's/players as the server blocks it, in this case we need to use a remote event

Example of This:

Make a remote event in ReplicatedStorage with the name of TicketExchange

1-- LocalScript
2local TicketExchange = game.ReplicatedStorage.TicketExchange
3script.Parent.MouseButton1Click:Connect(function()
4--[[ What's the need for this? ]]--
5-- script.Parent.Parent.PlayerName.Value = script.Parent.Parent.TextBox.Text
6local Name = script.Parent.Parent.PlayerName.Value
7TicketExchange:FireServer(tostring(Name)) -- We fire a remote event to the server, so the server can do the cloning part, the tostring() is to make sure it's a string, and numbers that are encapsulated (enclosed) in strings, because if we try to give a player with numbers in their name, it would likely turn out to be an error (malformed number)
8end)
1-- Script
2local TicketExchange = game.ReplicatedStorage.TicketExchange
3local Ticket = game.ReplicatedStorage.Ticket
4TicketExchange.OnServerEvent:Connect(function(Player, Name) -- Make a OnServerEvent, so we can actually have the server to do something, the 1st arg, is what player fired this remote event. Read more about it at : https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
5  print(Player.Name.. " has given " .. Name .. " a ticket.")
6    local TicketClone = Ticket:Clone()
7    TicketClone.Parent = game.Players[Name].Backpack
8end)
0
Thank you so much. You have given me the opportunity to complete a project I can't wait for. l1u2i3 52 — 5y
Ad

Answer this question