where would i put the scripts at?
Put the LocalScript inside of StarterPlayerScripts, then put the ServerScript inside of ServerScriptService
just tried it out and it works fine for me
in the ServerScript, you can delete the
eachcoin ~= nil and line, if you want the points to be picked up a bit faster
Would I need to make a loop because you need to open a crate for them to spawn?
What do you mean by that? I don’t think you have to.
There will be no gems in workspace so it wont detect any unless it gets updated right?
The script should work full time, if the for loop doesn’t find your specific object (or coin) in the workspace, then it will just return itself and not do anything else, so an extra loop isn’t really needed.
everything works except when the part is suppose to be deleted and adding the points. The event fires so im left confused
If possible, could you send me a place file so I can look more into the problem?
yeah let me put it into a baseplate Place - Roblox there you go
You didn’t have to add an extra loop, so I fixed that and now here is your ServerScript code:
local ServerStorage = game:GetService("ServerStorage") local Debounce = false local Collect = game:GetService("ReplicatedStorage").CollectEvent for _, eachcoin in pairs(workspace:WaitForChild("GemDrops"):GetChildren()) do if eachcoin:IsA("Part") then coroutine.resume(coroutine.create(function() eachcoin.Touched:Connect(function(hit) local human = hit.Parent:FindFirstChild("Humanoid") if (human ~= nil) and Debounce ~= true then Debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) print(player.Name) eachcoin:Destroy() Collect:FireClient(player,eachcoin) Debounce = false end end) end)) end end
Here is a video of me collecting the diamonds lol:
robloxapp-20230609-1204163.wmv (2.0 MB)
Why are you creating a coroutine?
You are just doing a loop that connects an event to a function. You don’t need a coroutine.
The coroutine is to make sure that the functions “function” all at once.
But they will function all at once without the coroutine.
Sometimes they won’t, so thats why I added it.
Well that shouldn’t happen. So unless it’s necessary (which I would try to find a way to fix the issue instead). It’s not really a good idea to have it, as it uses up more resources and creates more complexity.
Well, it still works eitherway, but what if the person would want to use a
while loop or anything that could disrupt the whole entire function? It would still be quite necessary if they are adding something that could disrupt the functionality of the script. The point on why I added the coroutine is not just because of its complexity, but because it can also help the person with other functions that they need to get through the system. Though, your not wrong at all, it works fine with out a coroutine, and I completely understand your point on it just being an extra resource.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.