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

Multi-person collecting object: how to work with server?

Asked by 5 years ago
Edited 5 years ago

So I'm making a collect-a-thon game however I have already hit a problem which is the fact that when I run the game only one person in the server can collect the items, once a player has collected the item, no one else can until the server is reset, I have tried to figure out what the problem is but to no avail so I ask you: How can I make this work? Do I need to use a local script or something else?

Bellow is the current script for my main collectable (no animation yet once you get it but this needs to be sorted out first).

local db = true

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 0.125
            script.Parent.CanCollide = false
            script.Parent.Color = Color3.new(75,75,75)
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats2.Clapperboards.Value = player.leaderstats2.Clapperboards.Value + 1
        end
    end
end)

Also the script is with the part in the workspace. I.e Workspace -> clapperboard ->collecting script.

The way the script currently works stops the player who collected it from trying to collect it again which is what I want.

Edit: ok the db problem is solved but that brings up the problem of how to stop the first player who collected it form collecting it again, also I don't know how to change the properties of the object so it only changes for the player who collects it.

0
You need to reset db. However if you do this, then the player can collect it multiple times. To fix this, add their name into a table, and check if their name is in there or not. If it is, don't let them collect it again. LawlR 182 — 5y
0
You could also change the properties locally so that other players don't get confused with which ones they have collected already. LawlR 182 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The issue is that you never set the debounce back to true.

Meaning your script is stuck here:

if db == true then

The condition is never met.

At the end after you do everything, set it back to true

local db = true
local part = script.Parent -- don't repeat yourself! use a variable

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and db then
        db = false
        part.Transparency = 0.125
        part.CanCollide = false
        part.Color = Color3.fromRGB(75,75,75)
        -- use fromRGB to use numbers from 0-255
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if player then -- might not be a player so you should check
            player.leaderstats2.Clapperboards.Value = player.leaderstats2.Clapperboards.Value + 1
        end
        wait(2) -- change to the time you want in seconds for it to reset
        db = true -- SETTING IT BACK TO TRUE
    end
end)

Finally, :connect() is deprecated, use :Connect().


Hopefully this answered your question and if it did, then don't forget to hit that "Accept Answer" button below. If you have any other questions then feel free to leave them down in the comments.
Ad

Answer this question