So I was trying to make a heal script so when you press the button you get healed
and as a code I used
hum.Health = hum.Health + 20
this works but after a few seconds I instantly get -20 health for some reason
Idk how to fix it but maybe someone can help me
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:03pm
2
Can I see your full script? charlimits
1 Like
Please send the entire script .
1 Like
n4dar
(MrWalkEmDown2Hell)
July 20, 2022, 5:06pm
4
I don’t think the plus symbol works like that, I think your gonna have to do it like this.
hum.Health = hum.Health += 20
For more you can look at here.
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:07pm
5
No, that operator definitely works, I’ve done something like that before
3 Likes
Please send it with copy and paste, that is hard to read.
1 Like
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
--
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://10290896074"
--
local playerMod = require(game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerMod:GetControls()
--
local sound = game.Workspace.Sound.Heal
--
local debounce = false
--
local remote = game.ReplicatedStorage:WaitForChild("Heal")
function onKeyPress(inputObject, gameProcessedEvent, data, client)
if inputObject.KeyCode == Enum.KeyCode.B then
if debounce then return end
debounce = true
remote:FireServer()
local Bandage = Instance.new("Part")
Bandage.Parent = char["Right Arm"].RightGripAttachment
Bandage.Size = Vector3.new(0.562, 0.262, 0.102)
local Bandage2 = Instance.new("SpecialMesh")
Bandage2.Parent = Bandage
Bandage2.MeshId = "rbxassetid://7168110358"
Bandage2.TextureId = "rbxassetid://7168111654"
Bandage2.Scale = Vector3.new(0.14, 0.142, 0.13)
local weld = Instance.new("Weld")
weld.Part0 = Bandage
weld.Part1 = char["Right Arm"]
weld.Parent = char["Right Arm"]
local Highlight = Instance.new("Highlight")
Highlight.Parent = char
Highlight.DepthMode = Enum.HighlightDepthMode.Occluded
Highlight.FillColor = Color3.fromRGB(0, 255, 0)
Highlight.FillTransparency = 0.5
Highlight.OutlineColor = Color3.fromRGB(255,255,255)
Highlight.OutlineTransparency = 0
controls:Disable()
sound:Play()
hum:LoadAnimation(anim):Play()
wait(3.3)
Bandage:Destroy()
Bandage2:Destroy()
controls:Enable()
Highlight:Destroy()
hum.Health = hum.Health + 20
wait(57.5)
debounce = false
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:10pm
9
How is char a parent of the script but also the player’s humanoid? Do you have this as a local script in StarterCharacterScripts?
1 Like
Yes I have it inside StarterCharacterScripts
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:14pm
11
Are there any errors in the output?
1 Like
no there are no errors in the output
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:21pm
13
I think the main error would be the one I quoted above, because even if it’s a local script in StarterCharacterScripts, the script wouldn’t be a parent of the humanoid
1 Like
Dfn150
(DevFunNewIdeas)
July 20, 2022, 5:25pm
14
Try changing it to game.Players.LocalPlayer
and then get the LocalPlayer’s characther
Aespect
(Aespect)
July 20, 2022, 5:37pm
15
If it works but changes your health after a few seconds, there’s likely another script involved that’s messing with this one, or it’s a very unique Roblox error. My guess is the first, so make sure this is the only script that’s interacting with the Player at this time.
1 Like
Nyonic
(Nyonic)
July 20, 2022, 5:59pm
16
DERKINGIMRING112:
remote:FireServer()
what does the server side of this do when the remote is fired?
whats the script section there?
it does seem you have some other script messing with the health