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

Why isn't my click-healing program working?

So I'm trying to make a script that heals the player your mouse is hovered over when you press a certain letter, but it's not working. The player isn't getting healed at all and no error messages are popping up. Any thoughts?

This code is in a local script.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Players = game:GetService("Players")
local UserInput = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HealPlayerDo")


UserInput.InputBegan:Connect(function(keycode)
    if keycode.KeyCode == Enum.KeyCode.H and Player.TeamColor == BrickColor.new("Mulberry") then
        local Hit = Mouse.Target
        if Hit then
		local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
            if Humanoid then
				local PlayerHit = Players:GetPlayerFromCharacter(Hit.Parent)
				local charr = Hit.Parent
				local name = PlayerHit.Name
				remoteEvent:FireServer(name)
            end
        end
    end
end)

This code is in a regular script.

ReplicatedStorage = game:GetService("ReplicatedStorage")
 
 remoteEvent = ReplicatedStorage:WaitForChild("HealPlayerDo")
 
 function onCreatePart(player, namee)
	game.Workspace.namee.Humanoid.Health = 100
	local og = game.Lighting.healing.heal
	local clone = og:Clone()
	clone.Parent = game.Workspace.namee:WaitForChild("UpperTorso")
	wait(3)
	clone:Destroy()
end
 	
	remoteEvent.OnServerEvent:Connect(onCreatePart)
	

I have a RemoteEvent too called "HealPlayerDo"

1 answer

✓ Accepted answer

This should fix the issue:

ReplicatedStorage = game:GetService("ReplicatedStorage")

 remoteEvent = ReplicatedStorage:WaitForChild("HealPlayerDo")
local Players = game:GetService("Players")
 function onCreatePart(player, namee)
	local PlayerGet = Players:GetPlayerFromCharacter(game.Workspace:FindFirstChild(namee)) --Gets the targeted character
	local Character = PlayerGet.Character or PlayerGet.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	Humanoid.Health = 100
    local og = game.Lighting.healing.heal
    local clone = og:Clone()
    clone.Parent = game.Workspace.namee:WaitForChild("UpperTorso")
    wait(3)
    clone:Destroy()
end

    remoteEvent.OnServerEvent:Connect(onCreatePart)

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