Hello So I have this Part or I have named it Tix so what i want is that I have the code but I have to duplicate them and place them around the map but there is a issue when i try touching the second Duplicated Part that one does not work but the original Part does work So Please Help Me This is Urgent If You need the code I will provide it Thank you (URGENT)
#I have a Tix I have to duplicate so many of them but if i try touching the other ones they dont work
21 messages · Page 1 of 1 (latest)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- VARIABLES --
local tixParts = workspace.TixParts
local removeTixClient = ReplicatedStorage.RemoveTixClient
local debounceTracker = {}
-- HANDLERS --
for i, v in tixParts:GetChildren() do
v.Touched:Connect(function(otherPart)
if debounceTracker[v] then
return
end
debounceTracker[v] = true
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
local player = Players:GetPlayerFromCharacter(humanoid.Parent)
if player then
if player.HasTouched.Value == true then
return
end
player.HasTouched.Value = true
player.leaderstats.Points.Value += 1
removeTixClient:FireClient(player)
task.wait(1)
debounceTracker[v] = nil
end
end)
end
Anyone
the problem is the for loop only runs once
so it doesn't check for the newly added tix
to fix this
you can just add a script inside of the tix
so when it gets duplicated the code will run for that part
try putting this code inside of the tix part
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
if Debounce then return end
Debounce = true
local Character = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
if Player.HasTouched.Value == true then
return
end
Player.HasTouched.Value = true
Player.leaderstats.Points.Value += 1
removeTixClient:FireClient(Player)
task.wait(1)
Debounce = false
end
end)
@thorn tide
Also do you want them to be able to touch more than one tix?
Because with your code the player is only able to touch one
no i only want it so they can only touch it one time
@mental cedar
Helo
the code that you gave me did not work for some reason
I can't post my Datastore
did you put it inside of the tix and if you did check the console for errors
@mental cedar