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

Healing Item Not doing anything at all?

ok so i have an apple(meshpart) in a folder in workspace and when i click on it, it is supposed to heal the player by 10 but it does absolutely nothing it doesn't even print

localscript:

script.Parent.ClickDetector.MouseClick:Connect(function()
	print("clicked")
	game.ReplicatedStorage.HealingEvents.SmallHeal:FireServer()
	print("sent")
	script.Parent:Destroy()
end)

script:

game.ReplicatedStorage.HealingEvents.SmallHeal.OnServerEvent:Connect(function()
	game.Players.PlayerAdded:Connect(function(plr)
		local hum = plr.Character.Humanoid
		game.Workspace.Sounds.Crunch:Play()
		hum.Health = hum.Health + 10
	end)
end)



Exact Directory of the apple is game.workspace.PreAlphaApples.Apple but i dont think that matters

3 comments

0

you can use .MouseClick in a server script

0

no need for a local script or remote event

0

Yeah don't abuse FireServer.

1 answer

✓ Accepted answer

1.) Local scripts won't work if it's a descendant of the workspace

2.) Why are you putting a PlayerAdded event in the function connected to OnServerEvent? The first argument of OnServerEvent is always the player who fired the event.

3.) You know, you could've done this all in a server-sided script:

-- server-sided script inside the apple

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:WaitForChild('Humanoid')
    
    hum.Health = hum.Health + 10
    workspace.Sounds.Crunch:Play()
    script.Parent:Destroy()
end)

4 comments

0

well dang thank you so much

0

If this worked, please accept this answer

0

"Local scripts won't work if it's a descendant of workspace". Not true. Only will when they're a descendant of a player character

1

^ yea, I know

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