So i have a problem when a local script just doesn’t run.
I’ve tried putting it pretty much in everywhere, where a local script can run, but still nothing.
Here’s is the problematic script
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")
local CollectableTag = CollectionService:GetTagged("Collectable")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local HumanoidRootPart = character.HumanoidRootPart
local minimum_distance = 6
local cooldown_time = 0.1
local cooldown = false
for _, collectable in pairs(CollectableTag) do
print(collectable) -- Even this doesn't work
collectable.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not cooldown then
cooldown = true
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false)
local Params = {Position = HumanoidRootPart.Position}
local CollectTween = TweenService:Create(collectable, Info, Params)
CollectTween:Play()
task.wait(0.5)
collectable:Remove()
print("Collected")
local collectedItem = game:GetService("ReplicatedStorage").Collectables:FindFirstChild(collectable.Name)
collectedItem.Parent = player.Backpack
wait(cooldown_time)
cooldown = false
end
end)
end
Why would you want this to run on the client? Apparently you’re parenting a Tool to your Backpack. AFAIK that wouldn’t work. This needs to be done on the server. Using Touched probably wouldn’t be a good idea either, but I need this information backed-up.
You haven’t even verified that the script isn’t being run (such as with a print call, for example). How are you able to claim that it doesn’t execute?
Another thing: you use player.Character, assuming the player has a character at all. They might have just joined the game and it hasn’t been loaded yet. This means player.Character would be nil, and your entire script would break (yey).
Some general advice: PascalCase for services / instances, camelCase for local variables (collectableTag, minimumDistance, etc.). Try to keep up a consistent variable naming style. I’d recommend you to give a read on the Roblox Lua Style guide (although one might argue it’s a bit outdated).
I did print statement as the literal first line of the loop and also like 10 others, but that was after the post and still nothing. Please read the script before replying. Also the touched function was from the old version of the script that i accidentally copied instead of the new one.