Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you make a local collection system?

Asked by 3 years ago
Edited 3 years ago

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

1
So you're creating a part locally, then checking for the touch on the server? Read what i've just said and i think you'll understand the issue. DinozCreates 1070 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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:

  • Mined parts are near the player
  • The player isn't teleporting around to unauthorized locations (ex to random spots within the mine)
  • The player isn't mining things faster than they're supposed to be able to
1
You could also 'assign' each part to the player using something as simple as a string inside the part checking the players name. DinozCreates 1070 — 3y
0
thanks for the advice, i would upvote if i could NeonPandaEyes331 21 — 3y
Ad

Answer this question