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

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

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

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

1 comment

0

On which script I must change to FindFirstChild?

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