I'm currently making a collection system so that when an object is mined by a player, only the player will see and be able to interact with the drops from the object.
The problem is that, the drops do appear, but the collection part by touching it does not work.
This is the local player script
local replicated_storage = game:GetService("ReplicatedStorage") local remote = replicated_storage:WaitForChild("Remotes"):WaitForChild("OnBroken") remote.OnClientEvent:Connect(function(itemType, number, node) if itemType == "Stone" then for i = 1, number, 1 do local item = replicated_storage.Ore1:Clone() item.Anchored = false item.Parent = game.Workspace item.CFrame = node.CFrame * CFrame.new(math.random(1,2), 0, math.random(1,2)) end end end)
and this is the script within the ore inside the replicatedstorage.
print('working') script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player game.Players:GetPlayerFromCharacter(hit.Parent) local stat = player.leaderstats.Cash stat.Value = stat.Value + 30 end end)
There are no error results or prints from the script within the ore.
i've tried disabling and reenabling the script
You need to figure out what you want done on the server vs the client. You could put that collection script on the client, except then for someone's money to save or be seen by others you'd have to have the client telling the server how much the player has -- but exploiters could just say "I have 1000000 cash" and the server couldn't tell if it's legitimate or not.
Some general tips here: https://scriptinghelpers.org/guides/how-to-use-remoteevents-properly
The highest quality solution (and hardest to implement) is to have the server generate what the parts are supposed to be for each player and then use RemoteEvents to pass this information along. The client then takes this "blueprint"/plan and actually generates the parts (which no one else sees), but notifies the server whenever the player mines a particular part (allowing the server to award cash). You can optionally protect against exploiting by making sure (on the server) that: