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

Why I cant give tool to player with equipped tool gui?

Asked by 3 years ago

I want to make a script that I can give a tool to player with equipped tool gui. When I press TextButton it nothing happens and on output doesnt print any error.

Here is localscript that is on tool:

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:FindFirstChildWhichIsA("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 = ""
        else
            NameBox.Text = ""
        end
    end
end)

And here is script that is in ServerScriptService:

game.ReplicatedStorage.GivePlayerItem.OnServerEvent:Connect(function(Player, PlayerName)
    local ToolToGive = Player.Character:FindFirstChildWhichIsA("CestovnyListok")
    ToolToGive:clone()
    ToolToGive.Parent.Parent = game.Players[PlayerName].Backpack
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

FindFirstChildWhichIsA is looking for a Class Type, not a string. What you're looking for here would be :FindFirstChild.

0
On which script I must change to FindFirstChild? testmiskobay 0 — 3y
Ad

Answer this question