For the first part, I’m simply trying to share a variable between a local and server script. The local script creates the variable, and then later on the server script has to use the variable. I’m not 100% sure on how to do this, so any help with this would be great.
I’m specifically trying to share the targetHum variable at the bottom of the local with the targetHum at the bottom of the server.
(By the way, the local fires a remote event to trigger the server script)
Local:
local aimFunction = mouse.Button1Down:Connect(function()
if tool.Parent == game.Workspace:WaitForChild(player.Name) then
if mouse.Target ~= nil then
local target = mouse.Target.Parent
local playerTargetRoot = target:FindFirstChild("HumanoidRootPart")
if target:FindFirstChildOfClass("Humanoid") then
if aiming == false then
local targetDistance = (playerTargetRoot.Position - playerRoot.Position).Magnitude
if distance <= range then
local targetHum = target:FindFirstChildOfClass("Humanoid")
Server:
if currentAmmo > 0 then
for i = 1, volley do
if currentAmmo > 0 then
print("Fired!")
flash.Enabled = true
dust.Enabled = true
smoke.Enabled = true
task.wait(0.05)
flash.Enabled = false
dust.Enabled = false
smoke.Enabled = false
currentAmmo = currentAmmo - 1
sounds.Fire:Play()
targetHum.Health = targetHum.Health - damage
Secondly, I’d like the targetHum and playerTargetRoot variable to update every time the aimFunction is ran. For a bit of context, this is a weapons script (obviously) and the player locks onto the target that they click on. Since the targetHum variable is already in the function, I’d expect it to update each time, but it simply doesn’t.
Help with either of these issues would be greatly appreciated!
TL;DR
Trying to share the targetHum variable between both scripts, while also updating the parent variable (playerTargetRoot) each time the function is ran.