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

How can I give tool to player wth tool that have screengui?

Asked by 2 years ago

Hello, I want help with script that player gives item to another player. Its tool with ScreenGui.

Here is script that is in ScreenGui (LocalScript):

local Player = game.Players.LocalPlayer
local ScreenGui = script.Parent.Parent
local NameBox = ScreenGui.Tlac.Hrac
local GiveButton = ScreenGui.Tlac.TextButton1

local function getPlayerFromPartialName(PartialName)
    local foundName = nil
    local Players = game.Players:GetPlayers()
    for i = 1, #Players do
        local PossiblePlayer = Players[i]
        if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
            foundName = PossiblePlayer.Name
        end
    end

    if not foundName then
        return nil
    else
        return foundName
    end
end
GiveButton.MouseButton1Click:Connect(function()
    if not Player.Character:FindFirstChild("CestovnyListok") then
        NameBox.Text = ""
    end
    local NameBoxText = NameBox.Text
    if NameBoxText ~= "" then
        local playerName = getPlayerFromPartialName(NameBoxText)
        if playerName then
            print("Found player")
            game.ReplicatedStorage.GivePlayerItem:FireServer(playerName)
            NameBox.Text = ""
        end
    end
end)

And here is script that is on ServerScriptService (GivePlayerItem):

game.ReplicatedStorage.GivePlayerItem.OnServerEvent:Connect(function(Player, PlayerName)

local ToolToGive = Player.Character:FindFirstChild("CestovnyListok")

ToolToGive:clone()

ToolToGive.Parent.Parent = game.Players[PlayerName].Backpack

end)

I’ve tried any tutorials that can help me with that, but nothing works.

Answer this question