#CollectionService:GetTagged isnt working
61 messages · Page 1 of 1 (latest)
Also, to detect if a tool is inside a backpack you can do:
if tool:FindFirstAncestorWhichIsA("Player") then —is a tool in a player
No its a local script
Make it server then
I cant tho
Why tho
Its made for hunger bar
???
Wait a
I dont get what you’re trying to do then
Line hunger
Is it a physical object
Or is it a variable
Its a gui frame
Bruh
I feel like you know nothin about scripting
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?
Yea probably
Do you have output open?
Does it happen to say ‘attempt to index nil with ‘wrap’
what is acoroutine tho?
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
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
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
wont the hunger value be same for each player then?
Noo
Make a seperate value for each player
LIKE A COINS SYSTEM
Just hunger and prob not a leaderstat
so put like an int value into a player
Yes
And on the client get the value through game.Players.LocalPlayer.Hunger
Instead of having it on the client
k
if i try to find Hunger inside a player in the server script it keeps appearing as nil
You need to create it
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
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
So I have to create the int value on server script instead then?
Yes