I'm attempting to create a tool that will explode wherever the user clicks. But I can't get the variable that tells where the player clicks into the 2nd script that actually makes the explosion.
I have 2 scripts, the first one being a Local Script which has this code in it
wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Explode")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local handle = script.Parent:WaitForChild("Handle")
local tool = script.Parent
local mouse = player:GetMouse()
local mousePos = mouse.Hit.p
mouse.Button1Down:Connect(function()
if tool.Activated then
local mousePos = mouse.Hit.p
remoteEvent:FireServer()
end
end)
The 2nd script being a regular script that actually creates the explosion so the explosion isn't client sided.
wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Explode")
remoteEvent.OnServerEvent:Connect(function()
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 30
explosion.ExplosionType = Enum.ExplosionType.NoCraters -- damages terrain
explosion.Position = mousePos
explosion.Parent = script.Parent
explosion.DestroyJointRadiusPercent = 100
explosion.BlastPressure = 400000
end)
I have tried using Global Variables, I have tried using stored values, but nothing I do seems to have worked resulting in frustrating errors. How would I fix this?

1 comment
are you trying to get LocalPlayer or other things that is client script only on a local script?