#CollectionService:GetTagged isnt working

61 messages · Page 1 of 1 (latest)

tidal estuary
#

Is this script a server script?

#

Also, to detect if a tool is inside a backpack you can do:

if tool:FindFirstAncestorWhichIsA("Player") then —is a tool in a player

broken jackal
tidal estuary
broken jackal
#

I cant tho

tidal estuary
#

Why tho

broken jackal
#

Its made for hunger bar

tidal estuary
#

???

broken jackal
#

Wait a

tidal estuary
#

I dont get what you’re trying to do then

#

Line hunger

#

Is it a physical object

#

Or is it a variable

broken jackal
#

Its a gui frame

tidal estuary
#

Hunger.Value is a gui frame?

#

What??

broken jackal
#

Bruh

tidal estuary
#

I feel like you know nothin about scripting

broken jackal
#
local CollectionService = game:GetService("CollectionService")

local Hunger = script.Parent:WaitForChild("Hunger")
local Bar = script.Parent:WaitForChild("CurrentHunger")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local function Update()
    Bar:TweenSize(UDim2.new(Hunger.Value / 100, 0, 1, 0), "Out", "Linear", 0)
end



acoroutine.wrap(function()
    while task.wait(2.5) do
        if Hunger.Value > 0 then
            Hunger.Value -= 1
            
            if Hunger.Value == 0 then
                repeat
                    humanoid:TakeDamage(10)
                    task.wait(1)
                until humanoid.Health == 0 or Hunger.Value > 0
                
            end
        end
    end
end)()

for tools, tool in pairs(CollectionService:GetTagged("Food")) do
    tool.Activated:Connect(function()
        local newVal = math.clamp(Hunger.Value + tool.Gain.Value, 0, 100 )
        
        tool.Enabled = false
        
        Hunger.Value = newVal
        task.wait(2)
        tool:Destroy()
    end)
end

Hunger:GetPropertyChangedSignal("Value"):Connect(Update)```
#

Does it help?

tidal estuary
#

Yea probably

#

Do you have output open?

#

Does it happen to say ‘attempt to index nil with ‘wrap’

broken jackal
#

yes

#

nope

tidal estuary
#

what is acoroutine tho?

broken jackal
#

oh wait a

#

sry i added a by accident

#

but if the tool is cloned CollectionService part doesnt work

#

even if the tool has the tag

tidal estuary
#

Just dont do the collection part and tool functionality in this script, and move the hunger value to the server

#

Also, wouldnt use collectionservice for this

#

Collection service is pretty heavyweight especially if there is alot of instances in your game

broken jackal
#

oh uh

#

i dont think it will work tho if i change the script into a server one

tidal estuary
#

Dont change the entire script into server

#

Just move the tool’s functionality to the server

#

And change the hunger value on the server

#

Like you would do with a coins system

#

Update a gui depending on a server wide value

broken jackal
#

wont the hunger value be same for each player then?

tidal estuary
#

Noo

#

Make a seperate value for each player

#

LIKE A COINS SYSTEM

#

Just hunger and prob not a leaderstat

broken jackal
#

so put like an int value into a player

tidal estuary
#

Yes

#

And on the client get the value through game.Players.LocalPlayer.Hunger

#

Instead of having it on the client

broken jackal
#

k

broken jackal
tidal estuary
#

You need to create it

broken jackal
#

i did create it

#
local Hunger = Instance.new("IntValue")
Hunger.Parent = player
Hunger.Name = "Hunger"
Hunger.Value = 100``` - local script
#
local value = game.Players.LocalPlayer.Hunger

local Hunger = value``` and server script
tidal estuary
#

Noo

#

You dont know server / client replication?

#

Server cannot see any changes that the client does

#

Therefor creating an instance on client, makes it so the server cannot see it

broken jackal
tidal estuary
#

Yes