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.
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()
.