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

Need help with my Admin Gui, gives an error (Unable to cast value to object), any help?

I have been working on this script, that gives btools when you click the button but it doesnt work and gives me an error before i even click anything (Unable to cast value to object), any help

This is the script.

playerPlayers = game.Players.LocalPlayer.Name

playerWorkspace = game.Workspace:GetFullName(playerPlayers)

player = game.Players.LocalPlayer

r = script.Parent

t = player.PlayerGui.AdminGui.Frame.NameSelect.Text

player2 = game.Players:GetPlayerFromCharacter(t)

player.PlayerGui.AdminGui.Frame.Btools.MouseButton1Click:Connect(function(p)

local e = game.Lighting["Building Tools"]:Clone()

e.Name = ("Btools")

e.Parent = player2.Backpack

end)

1 answer

✓ Accepted answer

I was normally going to provide you with a fix, but there are multiple problems in your script, so I re-coded it completely, delete the original script, create a localscript inside the Btools button and paste this code into it:

local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Button = script.Parent
local Frame = Button.Parent
local Gui = Frame.Parent
local NameSelect = Frame:FindFirstChild("NameSelect")

function GetPlayerFromName(PlayerName)
	local Player = nil
	if PlayerName then
		for i,v in ipairs(game.Players:GetPlayers()) do
			if string.lower(v.Name) == string.lower(PlayerName) then
				Player = v
			end
		end
	end
	return Player
end

Button.MouseButton1Click:Connect(function()
	local TargetPlayer = GetPlayerFromName(NameSelect.Text)
	if TargetPlayer then
		local Backpack = TargetPlayer:FindFirstChild("Backpack")
		if Backpack then
			local Btools = Lighting:FindFirstChild("Building Tools")
			if Btools then
				Btools:Clone().Parent = Backpack
			end
		end
	end
end)

1 comment

0

Thank you so much! This worked, i have been working on this for a day now so i came here for help.

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