So I have tried to work on the item that can be collected in a collect-a-thon however it's still not functioning the way I need it to,
the script is as follows:
local db = true local itemGot = false script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then -- check if a player has hit the object if db == true and itemGot == false 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 itemGot = true end wait(2) db = true end end)
The idea is once player 1 (the first player to collect it) has got the item said player 1 can't get that item again, however any other players that are on the server who haven't collected this item can still get it.
Note: I have added another variable to try and see if it would work but the script stops any other players collecting once player 1 collects it.
The idea is once player 1 (the first player to collect it) has got the item said player 1 can't get that item again, however any other players that are on the server who haven't collected this item can still get it.
(psss, hey there, if this answer helped you should accept)
itemGot
is only false
once. The moment a player touches the item, itemGot
is set to true
and never set back to false.
We can use a dictionary for this case to store the players who have collected the item. And we can check if the player touching the item is already in the playersWhoCollected
dictionary (or whatever you decide to name the variable).
local players = game:GetService("Players") local canTouch = true local playersWhoCollected = {} local item = script.Parent local function itemTouched(hit) if canTouch then canTouch = false local humanoid = hit.Parent:FindFIrstChild("Humanoid") if humanoid then local character = humanoid.Parent local player = players:GetPlayerFromCharacter(character) if player then if not playersWhoCollected[player] then --// update player leader stats playersWhoCollected[player] = true end end end wait(2) canTouch = true end end item.Touched:Connect(itemTouched)
Now for making the item disappear only for the person who touched we would want to use remote events. GoodCallMrOlson has pointed this out in the comments.
If you mean for the item to disappear (or transparent to .125), be non-collectible, and color change ONLY for the person who touches it. I would suggest Remote Events
Pseudo code you could use: makeItemInvisible:FireClient(client, item)
. Have a remote for making an item invisible and fire the client and have them make it invisible on their client.
local makeItemInvisibleEvent = ... --// reference to remote event local function makeItemInvisible(item) item.Transparency = .125 item.CanCollide = false item.Color = Color3.new(75, 75, 75) --// notice I used `Color3.fromRGB` and not `Color3.new` as you did since `Color3.new` accepts ranges from `[0, 1]` while `Color3.fromRGB` accepts ranges from `[0, 255]` end makeItemInvisibleEvent.OnClientEvent:Connect(makeItemInvisible)