Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why will my handto script give the player 2 points instead of one?

i made a simple handto script that will get the current tool the player is holding and give it to the player that they put in a gui, it doesnt give the other player the tool and the script gives 2 points instead of one.

--Local script

local player = game.Players.LocalPlayer
local playerName = script.Parent.Parent.PlayerName
local event = game.ReplicatedStorage:WaitForChild('HandToEvent')

script.Parent.MouseButton1Click:Connect(function()
	print('Button Pressed!')
	if game.Players:FindFirstChild(playerName.Text) then
		if  playerName.Text == player.Name then return end
			event:FireServer(playerName)
			print('Event fired!')
		end
end)
--Server

local event = game.ReplicatedStorage:WaitForChild('HandToEvent')

local function handTo(player, playerName) 
	local points = player.leaderstats.Points
	points.Value = points.Value + 1 
	print('Added points!')
	
	local tool
	
	for _, toool in pairs(player.Character:GetChildren()) do
		if toool:IsA('Tool') then
			tool = toool
		end
		
		tool.Parent = game.Players[playerName].Backpack
		print('Assigned tools parent to player!')
	end
end

event.OnServerEvent:Connect(handTo)

tysm if you can help!

1 answer

--Local script
local debounce = false
local player = game.Players.LocalPlayer
local playerName = script.Parent.Parent.PlayerName
local event = game.ReplicatedStorage:WaitForChild("HandToEvent")

script.Parent.MouseButton1Click:Connect(
    function()
        if debounce == false then
            debounce = true
            print("Button Pressed!")
            if game.Players:FindFirstChild(playerName.Text) then
                if playerName.Text == player.Name then
                    return
                end
                event:FireServer(playerName)
                print("Event fired!")
                wait(5)
                debounce = false
            else
                print("Please wait at max 5 seconds.")
            end
        end
    end
)

This discussion is preserved as it was. New answers, comments, and votes are closed.