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

Why is the tool not equipping on mouse click?

Hey there, me again, so this time I got a free model and edited the script a bit so when you click the starting screen button it would equip it, but I get this error

07:44:05.474 - StarterGui is not a valid member of Player

I know that means something is wrong with the local player but I can't seem to get to an answer to get the game.players. the players name here with the starter GUI there,

###Can someone debunk this myth?

The script is inside "my" knife, the code I edited makes them not able to de-equip it.

wait(1)
local screenGOOEY = game.Players.LocalPlayer.StarterGui.StartingScreen.screenthing
local playbutton = screenGOOEY.plzplaybutton
local tool = script.Parent
local player = game.Players.LocalPlayer
local hum = player.Character.Humanoid

tool.Equipped:connect(function(mouse)
	game:GetService("RunService").RenderStepped:connect(function()
		if not hum.Parent:FindFirstChild(tool.Name) then
			hum:EquipTool(tool)
		end
	end)
end)

if playbutton.MouseButton1Click then
	if not hum.Parent:FindFirstChild(tool.Name) then
			hum:EquipTool(tool)
	end
	print("knifeequiped on playbutton click hah")
end 

Thanks,

Narwhal

1 answer

✓ Accepted answer

Question

Why is the tool not equipping on mouse click?

Answer

Once again the problem is in the error.

07:44:05.474 - StarterGui is not a valid member of Player

The contents for a player's GUI is stored in a folder called PlayerGui in the player. Replace LocalPlayer.StarterGui with LocalPlayer.PlayerGui and it should work.

For some extra measures, throw in some :WaitForChild's to make sure it doesn't error if the code runs before the object's exist.

1 comment

1

Again, Thanks!

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