Hey Devs,
I am currently on an award system for a Race. The Script should give the Player +1 Point if he touched the Part. I made a local script for this because I want it that the remote event only fires 1 time and then repeats waiting until the Race got reset back. I added a delay for that but the problem is that when I put the script in a normal script in the award part, the debounce is not local (for example when 2 player hit the Part at the same time the first one who touched it gets the Points. It should work, but the Reward Part is in a Model, called Map1 in a Folder in ServerStorage. I have multiple maps, and 1 of them gets randomly parented to a Folder called RaceSystem in Workspace, every 60 seconds. Here is my Script: (also every Map has the same Reward Part)
local debounce = true
for i,v in pairs(game.Workspace.RaceSystem:GetChildren()) do
if v:IsA("Model") then
v.RewardPart.Touched:Connect(function()
if debounce == true then
game.ReplicatedStorage.RaceEvents.Points:FireServer()
debounce = false
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
debounce = true
end
end)
end
end
Sadly the script doesn’t works… Any help would be appreciated!
The Remote Event which gets fired (is in a Script in ServerScriptService):
I already explained that I only want that the player gets rewarded 1 Point only 1 Time. For this I have to add a debounce in a script in the “invisible wall”, but because the debounce is not local only 1 player will get the reward
v.RewardPart.Touched:Connect(function(p)
local plr = game.Players:GetPlayerFromCharacter(p.Parent)
if plr then
if debounce == true then
game.ReplicatedStorage.RaceEvents.Points:Fire(plr) -- 'Points' event must be bindable
debounce = false
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
debounce = true
end
end
end)
local debounce = true
script.Parent.Touched:Connect(function(p)
local plr = game.Players:GetPlayerFromCharacter(p.Parent)
if plr then
if debounce == true then
plr:WaitForChild("leaderstats").Points.Value += 1
debounce = false
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
debounce = true
end
end
end)
If I use this in the Part and a Person touched the Part. Does the debounce go = false for the local Player, so when another player touched the part he also gets the point s+ debounce, or is it so that debounce goes false for everyone?
Only one player can touch this part.
If you want to more players can touch it then use this:
local bouncedPlayers = {}
script.Parent.Touched:Connect(function(p)
local plr = game.Players:GetPlayerFromCharacter(p.Parent)
if plr then
if not table.find(bouncedPlayers, plr) then
plr:WaitForChild("leaderstats").Points.Value += 1
table.insert(bouncedPlayers, plr)
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
table.remove(bouncedPlayers, plr)
end
end
end)
The script u gave me which I marked as a solution creates a player table for each plr who touched the part if its not there. It also removes the player table if a new race starts. U added ,plr) in the table. Now i gave the functions above. I just add them in the function when no plr table is there. Do i have to add something in the (…,plr) table function?
local bouncedPlayers = {}
script.Parent.Touched:Connect(function(p)
local plr = game.Players:GetPlayerFromCharacter(p.Parent)
if plr then
if not table.find(bouncedPlayers, plr) then
plr:WaitForChild("leaderstats").Points.Value += 1
game.ReplicatedStorage.RaceEvents.Fade:FireClient(plr)
wait(1)
game.ReplicatedStorage.RaceEvents.Died:FireClient(plr)
HumanoidRootPart.CFrame = workspace.Checkpoints:FindFirstChild(tostring(plr:WaitForChild("TeleportedStage").Value)).CFrame + Vector3.new(0,3,0)
table.insert(bouncedPlayers, plr)
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
table.remove(bouncedPlayers, plr)
end
end
end)
local bouncedPlayers = {}
script.Parent.Touched:Connect(function(p)
local plr = game.Players:GetPlayerFromCharacter(p.Parent)
if plr then
if not table.find(bouncedPlayers, plr) then
table.insert(bouncedPlayers, plr)
plr:WaitForChild("leaderstats").Points.Value += 1
game.ReplicatedStorage.RaceEvents.Fade:FireClient(plr)
wait(1)
game.ReplicatedStorage.RaceEvents.Died:FireClient(plr)
HumanoidRootPart.CFrame = workspace.Checkpoints:FindFirstChild(tostring(plr:WaitForChild("TeleportedStage").Value)).CFrame + Vector3.new(0,3,0)
repeat wait()
until game.Workspace.RaceSystem.DestroyPart.CanCollide == true
table.remove(bouncedPlayers, plr)
end
end
end)