Hi, I am writing a script where upon pressing a key, a player explodes. The script works, but when I run a test with two clients, the client not exploding cannot see the explosion and does not get killed by it. On the other client, the explosion occurs, and the other player's body parts are seen to fly away.

I am using a ModuleScript. Upon pressing the key, a function is called to execute the explosion. I don't know how to call it from a localscript to enable it to be shown to all clients. When I execute the function from a script in the workspace, both clients see the explosion, so I have no idea what's going on.

Local script on Player

local Player = game:GetService'Players'.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Mouse = Player:GetMouse()
Enabled = true

local sound = Instance.new("Sound", Player)
sound.SoundId = "rbxassetid://907668984"
sound.MaxDistance = 5
sound.EmitterSize = 5

local sphere = Instance.new("Part")
sphere.Name = "MaxDistanceSphere"

Mouse.KeyDown:connect(function(key)
	Character = Player.Character or Player.CharacterAdded:Wait()
	if Enabled == false then return end
	key = key:lower()
	if key == "q" then
		sound:Play()
		wait(2.5)
		require(game.Workspace.ModuleScript):Explode(Character.HumanoidRootPart.Position)
	end
	
	wait(1)
	Enabled = true
end)

ModuleScript

local ExplodeModule = {}

function ExplodeModule:Explode(pos)
	local explosion = Instance.new("Explosion", game.Workspace)
		explosion.Position = pos
		explosion.BlastRadius = 6
end

return ExplodeModule

Any help is greatly appreciated, thanks.

4 comments

0

You need to make a server script create the explosion and use RemoteEvents or RemoteFunctions to communicate with it

0

AH okay, I'll try that. Thanks.

0

Also, KeyDown and connect are deprecated, use UserInputService / ContextActionService and Connect instead.

0

Alright, thanks.