Script Issue with Hand-To

Hey everyone! :wave:

I’m currently trying to make a hand-to GUI for my roleplay game on Roblox. When a player is holding out an item, inputs a customer’s username and presses a give button, it’ll make a GUI appear on the player who is receiving the items’ screen which’ll ask them if they ordered the item. When they click yes, it’ll hand the item to them, and when they click no, it won’t do anything. This script was recently working perfectly, but I recently decided to add in some code to prevent gamepass items from being handed. As a result of this, the script now does not work. The issue is that the confirm gui doesn’t pop up, meaning the ‘customer’ can’t receive the item. Note that it disappears from the player who’s handing its’ inventory but doesn’t trigger the GUI.

The scripts that I’m using are listed below, let me know if you have the adequate knowledge to provide assistance with this or if you have any questions!

Setup:
image

ServerScript:

local HandtoEvent = game.ReplicatedStorage.HandtoEvent
local ConfirmHandtoEvent = game.ReplicatedStorage.ConfirmHandtoEvent

HandtoEvent.OnServerEvent:Connect(function(Player, NameOfPlayerToGive)
    local PlayerToGive = game.Players:FindFirstChild(NameOfPlayerToGive)
    local Character = Player.Character
    local CurrentlyEquippedTool = Character:FindFirstChildWhichIsA("Tool")
    local ConfirmGUI = PlayerToGive.PlayerGui.ConfirmGUI
	
	if CurrentlyEquippedTool.Name == "Magic" then
		wait(1)
	elseif CurrentlyEquippedTool.Name == "SpeedCoil" then
		wait(1)
	elseif CurrentlyEquippedTool.Name == "GravityCoil" then
		wait(1)
	elseif CurrentlyEquippedTool.Name == "Mop" then
		wait(1)
	elseif CurrentlyEquippedTool.Name == "ManagementWacker" then
		wait(1)
	else
		ConfirmGUI.BackFrame.ConfirmText.Text = Player.Name .. " is handing you a " .. CurrentlyEquippedTool.Name .. ". Would you like to accept?"
		ConfirmGUI.PlayerWhoGaveItem.Value = Player.Name
		ConfirmGUI.ItemThatWasGiven.Value = CurrentlyEquippedTool
		CurrentlyEquippedTool.Parent = ConfirmGUI
	end
end)

ConfirmHandtoEvent.OnServerEvent:Connect(function(Player, Confirm)
	local ConfirmGUI = Player.PlayerGui.ConfirmGUI
	local NameOfPlayerWhoGaveItem = ConfirmGUI.PlayerWhoGaveItem.Value
	local ItemThatWasGiven = ConfirmGUI.ItemThatWasGiven.Value

	if Confirm == true then
		ItemThatWasGiven.Parent = Player.Backpack
		game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).leaderstats.Points.Value = game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).leaderstats.Points.Value + 1

		ConfirmGUI.PlayerWhoGaveItem.Value = ""
		ConfirmGUI.ItemThatWasGiven.Value = nil
	else
		ItemThatWasGiven.Parent = game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).Backpack
	end

	ConfirmGUI.Enabled = false
end)

LocalScript:

local GroupId = 000000 --Group Id Here
local MinimumRank = 0

local Player = game.Players.LocalPlayer

local PlayerNameBox = script.Parent.BackFrame.PlayerNameBox
local HandtoButton = script.Parent.HandtoButton

function getFullNameFromPartial(PartialName)
    local foundPlayer = nil

    local Players = game.Players:GetPlayers()
    for i = 1, #Players do
        local CurrentPlayer = Players[i]

        if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
            foundPlayer = CurrentPlayer.Name
            break
        end
    end

    return foundPlayer
end

if Player:GetRankInGroup(GroupId) < MinimumRank then
    script.Parent:Destroy()
end

HandtoButton.MouseButton1Click:Connect(function()
    local PartialName = PlayerNameBox.Text
    local FullName = getFullNameFromPartial(PartialName)

    if FullName ~= Player.Name and game.Players:FindFirstChild(FullName) then
        game.ReplicatedStorage.HandtoEvent:FireServer(FullName)
    end
end)
if CurrentlyEquippedTool.Name == "Magic" then
    wait(1)
else 
    if CurrentlyEquippedTool.Name == "SpeedCoil" then
        wait(1)
    else
        if CurrentlyEquippedTool.Name == "GravityCoil" then
            wait(1)
        else
            if CurrentlyEquippedTool.Name == "Mop" then
                wait(1)
            else 
                if CurrentlyEquippedTool.Name == "ManagementWacker" then
	                wait(1)
                else
                    ConfirmGUI.BackFrame.ConfirmText.Text = Player.Name .. " is handing you a " .. 
                    CurrentlyEquippedTool.Name .. ". Would you like to accept?"
	                ConfirmGUI.PlayerWhoGaveItem.Value = Player.Name
	                ConfirmGUI.ItemThatWasGiven.Value = CurrentlyEquippedTool
	                CurrentlyEquippedTool.Parent = ConfirmGUI
                end
            end
        end
    end
end

Try this. If it doesn’t work, try to put print() to see where the script reaches.

Also I suggest you to not edit GUIs from server. It can cause some problems.
Instead you should use another or the same event to change the text.

1 Like

Thank you for the response! Unfortunately, this didn’t work. I’m unsure as to why and I’m not receiving any errors.

The script before that was working before I edited it:

local HandtoEvent = game.ReplicatedStorage.HandtoEvent
local ConfirmHandtoEvent = game.ReplicatedStorage.ConfirmHandtoEvent

HandtoEvent.OnServerEvent:Connect(function(Player, NameOfPlayerToGive)
    local PlayerToGive = game.Players:FindFirstChild(NameOfPlayerToGive)

    local Character = Player.Character
    local CurrentlyEquippedTool = Character:FindFirstChildWhichIsA("Tool")

    local ConfirmGUI = PlayerToGive.PlayerGui.ConfirmGUI

    ConfirmGUI.Enabled = true
    print(ConfirmGUI.Enabled)
    ConfirmGUI.BackFrame.ConfirmText.Text = Player.Name .. " is handing you a " .. CurrentlyEquippedTool.Name .. ". Would you like to accept?"

    ConfirmGUI.PlayerWhoGaveItem.Value = Player.Name
    ConfirmGUI.ItemThatWasGiven.Value = CurrentlyEquippedTool

    CurrentlyEquippedTool.Parent = ConfirmGUI
end)

ConfirmHandtoEvent.OnServerEvent:Connect(function(Player, Confirm)
    local ConfirmGUI = Player.PlayerGui.ConfirmGUI
    local NameOfPlayerWhoGaveItem = ConfirmGUI.PlayerWhoGaveItem.Value
    local ItemThatWasGiven = ConfirmGUI.ItemThatWasGiven.Value

    if Confirm == true then
        ItemThatWasGiven.Parent = Player.Backpack
        game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).leaderstats.Points.Value = game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).leaderstats.Points.Value  + 1

        ConfirmGUI.PlayerWhoGaveItem.Value = ""
        ConfirmGUI.ItemThatWasGiven.Value = nil
    else
        ItemThatWasGiven.Parent = game.Players:FindFirstChild(NameOfPlayerWhoGaveItem).Backpack
    end

    ConfirmGUI.Enabled = false
end)

I recommend you to stop editing guis from the server since that can cause many problems.
Instead of changing it from the server, you can fire an event from the server to the client to send the handing message.

An example(from the same event, you can make another one):

Server:

local HandtoEvent = game.ReplicatedStorage.HandtoEvent
local ConfirmHandtoEvent = game.ReplicatedStorage.ConfirmHandtoEvent

HandtoEvent.OnServerEvent:Connect(function(Player, NameOfPlayerToGive)
    print("Got the event from the client")
    local PlayerToGive = game.Players:FindFirstChild(NameOfPlayerToGive)

    local Character = Player.Character
    local CurrentlyEquippedTool = Character:FindFirstChildWhichIsA("Tool")
    
    -- I also suggest that you should check the player's rank if you're doing this for a group game. https://developer.roblox.com/en-us/api-reference/function/Player/GetRankInGroup

    HandtoEvent:FireClient(PlayerToGive, player.Name, CurrentlyEquippedTool.Name)
end)

Client(You can make a local script in the gui or in starterpack):

local HandtoEvent = game.ReplicatedStorage.HandtoEvent

HandtoEvent.OnClientEvent:Connect(function(givingplayer, tool)
    print("Got the event from the server")
    if game.Players:FindFirstChild(givingplayer) then
   --[[ If its in the gui:

        local ConfirmGUI = script.Parent
        ConfirmGUI.Enabled = true

        If its in the starterpack(Recommended):

        local ConfirmGUI = game.Players.LocalPlayer.PlayerGui:WaitForChild("ConfirmGUI")
        ConfirmGUI.Enabled = true     ]]-

        ConfirmGUI.BackFrame.ConfirmText.Text = givingplayer.." is handing you a "..tool..". Would you like to accept?"

        ConfirmGUI.PlayerWhoGaveItem.Value = givingplayer
        ConfirmGUI.ItemThatWasGiven.Value = tool
    end
end)