Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Oficcer_F 207 Moderation Voter
5 years ago

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??

1
legend TheluaBanana 946 — 5y
0
wut Oficcer_F 207 — 5y

1 answer

Log in to vote
2
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

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)
1
Yeah I figured that out like 2 seconds after I published it lol, but thanks for answering anyway! Oficcer_F 207 — 5y
0
Thanks for accepting the answer, if anyone else stumbles upon this they can learn from it too aazkao 787 — 5y
Ad

Answer this question