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

How do you change a gui with a Remote Event?

Hello, I am trying to create a script that makes a health bar go down after a sand block gets clicked. Here is the server script:

game.ReplicatedStorage.ChangeSandGui.OnServerEvent:connect(function(player, x)
local part = game.Workspace.Sand[x]
part.Health.Value = part.Health.Value - 2
local val = part.Health.Value
local value = val/10
player.PlayerGui.SandHealth.Frame.TextLabel:TweenSize( UDim2.new(value,0, 1,0))
if val <= 0 then
	wait(.9)
	part:Destroy()
end
end)

When I test it in studio, everything works. When I play on a normal server, the output says "SandHealth is not a valid member of PlayerGui". Any ideas why it isn't working?

5 comments

0

You can't access the PlayerGui from the server in FE. User remotes to update the GUI.

0

Do I need a script in the remote event? I dont really understand how this works

0

Thanks for the replies. This is a script fired by a remote event that’s why I have no idea how this will work

0

You really don't need the server side at all.

1 answer

✓ Accepted answer

As hiim said, you don't need to use remote events, as you can do it all on the client. For example, instead of getting the sand block through the script's Parent, you could do something like this in a local script:

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
	if mouse.Target and mouse.Target.Name == "SandBlockNameHere" then
		--reduce health bar
	end
end)

2 comments

0

thats wrong sorry sexy

0

fixed it just for you love <3

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