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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
--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
)

Ad

Answer this question