I’ve been stuck on this for hours. I’m firing a remote event that does damage from a module in the replicated storage, and it works well on Roblox Studio. Problem is that when I join my roblox game to test it out, it doesn’t work. I’m not getting any errors in both Studio and the game, and I’ve tried publishing and shutting down my game to see if it’s an older version. What am I doing wrong?
Roblox Studio:
Roblox game:
Could you show us your code locally and on the server side?
The module that is called from the client:
fist.HitBox = function(plr) local hitPlayers = {} local char = plr.Character local root = char.HumanoidRootPart spawn(function() for i = 0, SwingSpeed, .1 do local region = rRegion3.new(root.CFrame * CFrame.new(0,0,-3), Vector3.new(4,5,3)) --DEBUGGING if debug == true then local hb = Instance.new("Part", game.Workspace) hb.Size = region.Size hb.CFrame = region.CFrame hb.CanCollide = false hb.Anchored = true hb.Transparency = .5 hb.BrickColor = BrickColor.new("Bright red") game:GetService("Debris"):AddItem(hb, .1) end --DEBUGGING local parts = region:FindPartsInRegion3(char, 1000) for _, part in pairs(parts) do local hChar = part.Parent local hHum = hChar:FindFirstChild("Humanoid") if hHum and hHum.Health > 0 and hitPlayers[hChar.Name] == nil then hitPlayers[hChar.Name] = hChar end end for playerName, hChar in pairs(hitPlayers) do if hChar ~= "Hit" then game.ReplicatedStorage.Remotes.WeaponRemotes.MeleeDamage:FireServer(tick(), hChar, Damage, hitSound) hitPlayers[playerName] = "Hit" end end wait(.1) region = nil end end) end
My remote handler(Not sure why it removed all the indents lol):
game.ReplicatedStorage.Remotes.WeaponRemotes.MeleeDamage.OnServerEvent:Connect(function(plr, clientTick, hChar, damage, soundId)
if tick()-clientTick > 1 then return end
local hHum = hChar.Humanoid
local hRoot = hChar.HumanoidRootPart
if hChar:FindFirstChild("Blocking") == nil then
hHum:TakeDamage(damage)
local hitSound = Instance.new("Sound", hRoot)
hitSound.MaxDistance = 100
hitSound.SoundId = "rbxassetid://"..soundId
hitSound.Volume = .5
hitSound:Play()
else
local blockSound = Instance.new("Sound", hRoot)
blockSound.MaxDistance = 100
blockSound.SoundId = "rbxassetid://3041192327"
blockSound.Volume = .5
blockSound:Play()
end
end)
What’s the purpose of the tick() check? You might find if you print tick on the client and the server you get slightly different answers.
It’s local to the computer it is being run on, and it’s been known for Roblox servers to be minutes out before.
Also, enclosing your code in three backticks ``` will make it format correctly here.
The purpose of that was to check for lag switching. If the difference between the client and server was too long, then i’d stop the script from running. I’ve tried removing it before, but it still doesn’t work in the actual game.
Turns out the tick() was the problem! I decided to give it another try and realized I didn’t properly remove it last time.