Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this script run on both the client and the server simultaneously?[FilteringEnabled]

local generator = script.Parent.Parent
local hum = script.Parent
local StatusGUI = generator.StatusGUI
local bar = StatusGUI.background.bar
local bar2 = StatusGUI.background.bar2

local recharge = script.recharge

function status()
bar:TweenSize(UDim2.new(hum.Health/hum.MaxHealth,0,1,0, "Out","Quad"))
	StatusGUI.background.title.Text = generator.Name	
		if hum.Health >= 0.7 * hum.MaxHealth then
			bar.BackgroundColor3 = Color3.fromRGB(0,255,0)
		elseif hum.Health < 0.7 * hum.MaxHealth and hum.health > 0.5 * hum.MaxHealth then
			bar.BackgroundColor3 = Color3.fromRGB(255,255,0)
		elseif hum.Health < 0.5 * hum.MaxHealth and hum.health > 0.3 * hum.MaxHealth then
			bar.BackgroundColor3 = Color3.fromRGB(255,170,0)
		elseif hum.Health < 0.3 * hum.MaxHealth then
			bar.BackgroundColor3 = Color3.fromRGB(255,0,0)
		end
		if hum.Health > 0 then
			workspace.FF.Transparency = .45
			workspace.FF.CanCollide = true
		elseif hum.Health == 0 then
			workspace.FF.Transparency = 1
			workspace.FF.CanCollide = false
		end
	end
		
hum.HealthChanged:Connect(status)

while wait(0.12) do
bar2:TweenSize(UDim2.new(recharge.Value/hum.MaxHealth,0,0.25,0, "Out","Quad"))
if hum.Health == 0 and recharge.Value < hum.MaxHealth then
	recharge.Value = recharge.Value + 1
elseif recharge.Value == hum.MaxHealth then
	recharge.Value = 0
	hum.Health = hum.MaxHealth
end
end

2 comments

0

What does your nice script do

0

Basically, I'm a clanscrub. I'm building Force Field Generators for my Clan Valkan. They're a crucial part of my Raid System that I am working on from scratch. The Generator script does work in Server Mode but I need it to also work in Client Mode.

1 answer

✓ Accepted answer

Okay revising my answer now based on what you have told me.

So inorder to fix the client not seeing it as an animate objects you might have to get rid of that humanoid and make your own 'fake humanoid' How I would do this is insert two NumberValue that represents the MaxHealth and Health into the Generator.

So the MaxHealth would be like 10 and then whenever someone attacks the generator the health keeps going down from there. As for the regeneration of the Health you would just use your while loop and make the Health increase until it reaches max health.

You would have to connect that health to the status's health. From there you can make it to where whenever the player attacks the Generator, the numbervalue changes, and when that number value changes the billboard gui changes as well.

If you want the player to be able to interact with a Billboard Gui it must be in the startergui. If not you can just leave it inside of the generator.

Make sure the billboardgui is in the StarterGui folder as so: --Only if the player can edit it https://gyazo.com/8af0b7e47975d72f66f9f6a0681ea4b1

  1. Inside of the player, you would put a localscript and inside of it make sure that everytime the generator's health changes the player recognizes it.

EX:

local Plr = game.Players.LocalPlayer
repeat wait() until Plr.Character
local Char = Plr.Character
local Hum = Char:WaitForChild('Humanoid')
local Generator = --where the generator is located in workspace or wherever
local GenHumanoid = Generator.Humanoid
local StatusGui = StarterGui.StatusGUI
function status ()
--blah blah
end
GenHumanoid.HealthChanged:Connect(function()
	Status()
end)

This will connect you locally to your generator's humanoid. The player can change the generator's health from the client by exploiting but it won't be updated to the server. That being said the change in health that player may see from doing so won't be the ACTUAL health.

9 comments

0

Let me explain what this script does. So the script is part of a Generator I built that is supposed to be destroyable by Raiders. The Humanoid I am targetting is the one within the Generator, not the player. Problem is, when I play in Client Mode the script doesn't work, but when I run it in Server mode it does.

0

The script is actually inside the Humanoid that's in the Generator. I felt using a Humanoid was the best course of action to make an Object have health

0

so what exactly is happening on the server that's not replicating to the client?

0

The entire script works in the server, but not the client. The client just sees it as an inanimate object.

0

Okay I'm changing my previous answer to what you might need. I think you may need to create your own fake humanoid.

0

Okay that should hopefully have solved your answer

0

please upvote if it helped ;)

0

So apparently, I didn't need to do anything to the script above. For some reason it worked just fine in an actual place visit. But not in the studio. So I am guessing it'll be fine...Thank you!

0

glad everything is working fine then, enjoy!!

This discussion is preserved as it was. New answers, comments, and votes are closed.