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

Players.Oficcer_F.Backpack.BananaDropper.DropBanana:15: attempt to compare number with userdata?

Trying to only be able to place 3 bananas on the ground, and then remove the tool and then needing to buy the tool every time... This is my local script:

tool = script.Parent
player = game.Players.LocalPlayer
replicatedSotrage = game.ReplicatedStorage
script.Parent:WaitForChild("BananLeft")
BananLeft = script.Parent.BananLeft
tool.Equipped:Connect(function(mouse)
mouse.Icon = "rbxgameasset://Images/MouseIconBanana"
player.PlayerGui.ScreenGui.BananCounter.Visible = true
mouse.Button1Down:Connect(function()

local position = mouse.Hit.p
local head = player.Character.Head
local distance = (head.Position - position).magnitude
if distance < 25 and BananLeft  > 0 then

	
replicatedSotrage.SpawnBanana:FireServer(position)
BananLeft.Value = BananLeft.Value - 1


	end
	if BananLeft.Value == 0 then
		game.ReplicatedStorage.DestroyTool:FireServer(player.Backpack.BananaDropper, player.StarterGear.BananaDropper)
		
	end
	
end)
end)

tool.Unequipped:Connect(function(mouse)
	
	player.PlayerGui.ScreenGui.BananCounter.Visible = false
	
end)

Server script:


replicated = game.ReplicatedStorage.SpawnBanana.OnServerEvent:Connect(function(player, position)
	local banana = game.ServerStorage.Banana:Clone()
	banana.Parent = game.Workspace
	banana.Position = Vector3.new(position.X, position.Y, position.Z)
end)


game.ReplicatedStorage.DestroyTool.OnServerEvent:Connect(function(player, backpackTool, starterGearTool)
	
	backpackTool:Destroy()
	starterGearTool:Destroy()
end)

This is the tool ancestry:

BananaDropper (Tool) DropBanana (Local script) BananLeft (IntValue) Handle (Part)

Please help Thanks Is this osmething with that the intValue is inside the player??

2 comments

1

legend

0

wut

1 answer

✓ Accepted answer

You are comparing an instance to a number, you have to get the value of the instance to compare it to a number

tool = script.Parent
player = game.Players.LocalPlayer
replicatedSotrage = game.ReplicatedStorage
script.Parent:WaitForChild("BananLeft")
BananLeft = script.Parent.BananLeft
tool.Equipped:Connect(function(mouse)
mouse.Icon = "rbxgameasset://Images/MouseIconBanana"
player.PlayerGui.ScreenGui.BananCounter.Visible = true
mouse.Button1Down:Connect(function()

local position = mouse.Hit.p
local head = player.Character.Head
local distance = (head.Position - position).magnitude
if distance < 25 and BananLeft.Value  > 0 then--------


replicatedSotrage.SpawnBanana:FireServer(position)
BananLeft.Value = BananLeft.Value - 1


    end
    if BananLeft.Value == 0 then
        game.ReplicatedStorage.DestroyTool:FireServer(player.Backpack.BananaDropper, player.StarterGear.BananaDropper)

    end

end)
end)

tool.Unequipped:Connect(function(mouse)

    player.PlayerGui.ScreenGui.BananCounter.Visible = false

end)

2 comments

1

Yeah I figured that out like 2 seconds after I published it lol, but thanks for answering anyway!

0

Thanks for accepting the answer, if anyone else stumbles upon this they can learn from it too

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