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
4 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.

    -------Down below is the script that I used for giving the ticket to the player and getting its username.

        -------------------------------Getting Player's Name and Giving Ticket

        script.Parent.MouseButton1Click:Connect(function()
            script.Parent.Parent.StringValue.Value = script.Parent.Parent.TextBox.Text

        -----Getting username inserted in the TextBox into a StringValue


        wait()
            local Name = script.Parent.Parent.PlayerName.Value
                                        --- Getting the value from the StringValue
            local TicketToGive = game.Players:WaitForChild(Name)
                                        --- Finding Player
        local Clone = game.ReplicatedStorage.Ticket:Clone()
                                        ---Cloning the Ticket from Replicated Storage
            Clone.Parent = TicketToGive.Backpack
                                        ---Giving the Cloned Ticket to the Player.
        end)

0
did you look into remote events? Fad99 286 — 4y

1 answer

Log in to vote
1
Answered by
cegberry 432 Moderation Voter
4 years ago
Edited 4 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

-- LocalScript
local TicketExchange = game.ReplicatedStorage.TicketExchange
script.Parent.MouseButton1Click:Connect(function()
--[[ What's the need for this? ]]--
-- script.Parent.Parent.PlayerName.Value = script.Parent.Parent.TextBox.Text 
local Name = script.Parent.Parent.PlayerName.Value
TicketExchange: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)
end)
-- Script
local TicketExchange = game.ReplicatedStorage.TicketExchange
local Ticket = game.ReplicatedStorage.Ticket
TicketExchange.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
  print(Player.Name.. " has given " .. Name .. " a ticket.")
    local TicketClone = Ticket:Clone()
    TicketClone.Parent = game.Players[Name].Backpack
end)
0
Thank you so much. You have given me the opportunity to complete a project I can't wait for. l1u2i3 52 — 4y
Ad

Answer this question