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?
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)