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

Script not working, can someone help? [ The "1 Answer" is an attempted fix ]

This script is used in hudzell's Parkour Battles as a healing script

-- UPDATE, SCROLL DOWN --

What is wrong with this LocalScript that makes it work properly only in solo mode but acts like it's a button with no script in multiplayer?

local button = script.Parent
player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
local Blur = script.Parent.Parent.Blur

function onClicked()
	Heal()
end

button.MouseButton1Click:connect(onClicked)

function Heal()
	if script.Parent.Text == "Heal" then
		script.Walkspeed.Value = character.Humanoid.WalkSpeed
		character.Humanoid.WalkSpeed = 0
		Blur.Visible = true
		Blur.BackgroundTransparency = .5
		local healFire = script.HealFire:Clone()
		local healLight = script.HealLight:Clone()
		local healSparkles = script.HealSparkles:Clone()
		healLight.Parent = character.Torso
		healFire.Parent = character.Torso
		healSparkles.Parent = character.Torso
		for i = 1, 100 do
			local newHealth = character.Humanoid.Health + 2
			if newHealth < 100 then
				wait(.001)
				character.Humanoid.Health = newHealth
			else
				character.Humanoid.Health = character.Humanoid.MaxHealth
			end
		end
		Blur.Visible = false
		Blur.BackgroundTransparency = 1
		healFire.Enabled = false
		healLight.Enabled = false
		healSparkles.Enabled = false
		character.Humanoid.WalkSpeed = script.Walkspeed.Value
		button.Text = "Wait: 5"
		wait(1)
		button.Text = "Wait: 4"
		wait(1)
		button.Text = "Wait: 3"
		wait(1)
		button.Text = "Wait: 2"
		wait(1)
		button.Text = "Wait: 1"
		wait(1)
		healFire:remove()
		healLight:remove()
		healSparkles:remove()
		button.Text = "Heal"
	end
end


Update: I changed the script a little at the top

local button = script.Parent
player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
local Blur = script.Parent.Parent.Blur

script.Parent.MouseButton1Down:connect(function()
	if script.Parent.Text == "Heal" then
		script.Walkspeed.Value = character.Humanoid.WalkSpeed
		character.Humanoid.WalkSpeed = 0
		Blur.Visible = true
		Blur.BackgroundTransparency = .5
		local healFire = script.HealFire:Clone()
		local healLight = script.HealLight:Clone()
		local healSparkles = script.HealSparkles:Clone()
		healLight.Parent = character.Torso
		healFire.Parent = character.Torso
		healSparkles.Parent = character.Torso
		for i = 1, 100 do
			local newHealth = character.Humanoid.Health + 2
			if newHealth < 100 then
				wait(.001)
				character.Humanoid.Health = newHealth
			else
				character.Humanoid.Health = character.Humanoid.MaxHealth
			end
		end
		Blur.Visible = false
		Blur.BackgroundTransparency = 1
		healFire.Enabled = false
		healLight.Enabled = false
		healSparkles.Enabled = false
		character.Humanoid.WalkSpeed = script.Walkspeed.Value
		button.Text = "Wait: 5"
		wait(1)
		button.Text = "Wait: 4"
		wait(1)
		button.Text = "Wait: 3"
		wait(1)
		button.Text = "Wait: 2"
		wait(1)
		button.Text = "Wait: 1"
		wait(1)
		healFire:remove()
		healLight:remove()
		healSparkles:remove()
		button.Text = "Heal"
	end
end)


4 comments

0

Is this a LocalScript? What is it supposed to do that it is not doing?

0

It's not doing anything in multiplayer, it acts like it's a button with no script in it. But in solo mode it works perfectly.

0

Does anyone know a place output GUI that I can use? I might be able to figure it out if I can find one.

0

Wow, thank you so much Bebee2, it worked! :D

2 answers

✓ Accepted answer

Huh... My post didn't post.

So the problem most likely is that you declared player before player actually fully loaded.

It's a common error with local scripts in PlayerGui or Backpack that defines player at the top.

What you do is just add this one-liner to the top:

repeat wait() until game.Players.LocalPlayer

Tell us what happens now.

1 comment

0

And it never hurts to use WaitForChild when declaring objects. I don't run into that problem as much, though.

[ DID NOT WORK ]

Wait a minute, I think I figured it out. The

function onClicked()
    Heal()
end

button.MouseButton1Click:connect(onClicked)

is above the actual function it's self (Heal()). So if I just use the updated script rather than the original, it should work, am I correct?

Sadly, this did not work. I still need help. :c

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