My script is meant to say that if you're already holding a bag, you can't open another crate. It isn't working. All I get when MouseHoverEnter is an error saying 'Bag is not a valid member of Folder'. Here is the code:

script.Parent.MouseClick:Connect(function(click)
	if game.Players[click.Name].PlayerGui.InteractionMenu.Interact.Text == "Click to break open" and script.Parent.Parent.Position == script.RegularPosition.Value then
		script.Parent.Parent.RotVelocity = Vector3.new(10, 10, 10)
		script.Parent.Parent.Thwack:Play()
		wait(1)
		local Bag = Instance.new("StringValue")
		local num = math.random(1,3)
		Bag.Name = "Bag"
		Bag.Parent = game.ReplicatedStorage.PlayerInventories[click.Name]
		if num == 1 then
			Bag.Value = "Money"
		elseif num == 2 then
			Bag.Value = "Weapons"
		elseif num == 3 then
			Bag.Value = "Bombs"
		end
		script:Destroy()
	end
end)

script.Parent.MouseHoverEnter:Connect(function(click)
	game.Players[click.Name].PlayerGui.InteractionMenu.Enabled = true
	game.Players[click.Name].PlayerGui.InteractionMenu.Item.Text = "Crate"
	if game.ReplicatedStorage.PlayerInventories[click.Name].Bag ~= nil then
		game.Players[click.Name].PlayerGui.InteractionMenu.Interact.Text = "You are already holding a bag"
	else
		game.Players[click.Name].PlayerGui.InteractionMenu.Interact.Text = "Click to Open"
	end
end)

script.Parent.MouseHoverLeave:Connect(function(click)
	game.Players[click.Name].PlayerGui.InteractionMenu.Enabled = false
end)

What's going wrong? Please help! Otherwise, the event won't work!

2 comments

1

Are you using leaderstats? Are you using PlayerAdded? Are you showing all of the code? Please provide more of an explanation. Also, what line is the error?

0

A possible fix could be Folder:WaitForChild()