I’m currently making a speeding wall type game, the problem is when the wall hits you. The module will (in this case) fire to the client to fling the player, the problem lies in the fact if the this function is ever called again, thee local script will print but not sit the player of fling the player?!
Module: (server)
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
te = nil
local module = {}
local events = {
Crazy = function(plr : Player)
replicatedStorage.Events.FlingPlayer:FireClient(plr)
end,
Angry = function(plr : Player)
local char = plr.Character
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end,
}
local debounceTable = {}
local function removeDB(plr)
wait(1)
debounceTable[plr] = nil
end
function module.Event(reset, name : string, wall : Part)
if reset == true then
if te then
te:Disconnect()
end
return
end
te = wall.Touched:Connect(function(part)
local plr = players:GetPlayerFromCharacter(part.Parent)
if plr and not debounceTable[plr] then
--Checks if the function is there
if events[name] then
debounceTable[plr] = plr
-- Runs function
events[name](plr)
removeDB(plr)
end
end
end)
end
return module
Client:
local replicatedStorage = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local function fling()
print("hm")
char.Humanoid.Sit = true
char.PrimaryPart.Velocity = Vector3.new(0,200,200)
end
replicatedStorage.Events.FlingPlayer.OnClientEvent:Connect(function()
fling()
end)
Works the first time but from then on it only prints!