I've been working on a health kit the past 2 weeks (learning a lot) and I've come across two problems.
- The remote events still fire when the health kit is unequipped.
- I can't figure out a way for my server script to read a client side variable.
On the 2nd issue, I created a gui to display a percentage when the player heals, but I can't figure out a way to make the server side script read it and change it during the while true do loop. Once it reaches 100%, the player will be fully healed. (Player would be holding down their mouse)
--[Main script]--
local RemoteEvent1 = script.Parent:WaitForChild("IsMouseHeldDown")
local RemoteEvent2 = script.Parent:WaitForChild("IsMouseReleased")
local RemoteEvent3 = script.Parent:WaitForChild("HealingCharge")
local MouseReleased = false
RemoteEvent2.OnServerEvent:connect(function(player)
MouseReleased = true --if mouse is released, set it to true
end)
RemoteEvent1.OnServerEvent:connect(function(player)
if MouseReleased == true then --if mouse isn't held down, set it back to false.
MouseReleased = false
end
local hum = player.Character:FindFirstChild("Humanoid")
while true do
wait(0.1)
--(somehow access the player's local script GUI percentage)----
if MouseReleased == true then --if mouse is released, break the loop.
break
end
end
end)
--[Local script]--
local player = game.Players.LocalPlayer
local Charge = 0 --[this is the percentage for the healing charge]
local healthGui = Instance.new("ScreenGui")
local percentage = Instance.new("TextLabel")
local text = Instance.new("TextLabel")
percentage.Size = UDim2.new(0,200,0,25)
percentage.Position = UDim2.new(0.438,0,0.525,0)
percentage.Text = Charge
percentage.TextSize = 25
percentage.Font = "SciFi"
percentage.TextColor3 = Color3.new(1, 1, 1)
percentage.BackgroundTransparency = 1
text.Size = UDim2.new(0,200,0,25)
text.Position = UDim2.new(0.438,0,0.577,0)
text.Text = "Healed"
text.TextSize = 25
text.Font = "SciFi"
text.TextColor3 = Color3.new(1, 1, 1)
text.BackgroundTransparency = 1
--healthGui.Enabled = false
percentage.Parent = healthGui
text.Parent = healthGui
healthGui.Parent = player.PlayerGui
local UserInputService = game:GetService("UserInputService")
local RemoteEvent1 = script.Parent:WaitForChild("IsMouseHeldDown")
local RemoteEvent2 = script.Parent:WaitForChild("IsMouseReleased")
local RemoteEvent3 = script.Parent:WaitForChild("HealingCharge")
local tool = script.Parent
tool.Equipped:connect(function()
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent1:FireServer()
end
end)
end)
tool.Equipped:connect(function()
UserInputService.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent2:FireServer()
end
end)
end)

5 comments
Why does your local script have identical chunk of lines near the bottom? You mentioned that the remote events still fire when the heatlh kit is unequipped, but I don't see no unequip. To read the client side variable can't you just access it on the server through the PlayerGui?
The identical lines is two seperate remote events for detecting whether the mouse is held down or released. I didn't think about trying to access it in the PlayerGui, i'll try it out now.
Server doesn't recognize the health gui in player gui, so I'll try to figure out a way storing a value to be accessed by both scripts in the tool itself.
That's unfortunate. Maybe you can utilise RemoteFunctions. Send the remote, return it back on the client, update the gui?
Seems like that'd be exactly what I need, client to server then back to client again. Time to learn.