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

Not going through the server?

Yesterday night I sent a request for a heal brick. Someone answered with it might not be going through to the server. In studio AND in a game my character takes damage on screen it looks like it. But it didn't go through to the server thous when I touch the heal brick it doesn't heal unless manually done through the developer console. The damage scripts are done through Local Scripts & the Heal done through a script. Any help is appreciated.

Heal Script:

script.Parent.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
		game.ReplicatedStorage.HealEvent:FireServer()
        hum.Health = hum.Health + 100
    end
end)

It works if manually done through the dev console & or through current client in studio to change health.

7 comments

0

Use remoteevents?

0

What do you mean?

0

Like how would I use remote events?

0

When changing a value, you must put it through a remote event and access it. Put a remote event into storage, "healthchanged" or something like that. Make a folder called events, put it into the folder. Then type "game.Replicatedstorage.Events.healthchanged:FireServer()" Then it should work. PS: put the code before "hum.Heath = hum.Health = hum.Health + 100

0

I don't think it worked I'll put in edit

0

You do NOT need a remote event for this.

0

It will give you another error. Assuming this is not a local script because it shouldn't be.

2 answers

If you have it inside of a Server sided script inside of the brick it will work as Tocuhed can be run through a server script

2 comments

0

So what you're saying is put the script in ServerScriptService then define the part being touched?

0

no put the server script in the part. Though actually via server script service it would work

Assuming the script to damage is going to the server correctly and you're using ROBLOX's Humanoid.Health as a base:

SERVER SIDE ONLY

Server Script under the HealBrick in Workspace

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		hum.Health = hum.Health + 100
	end
end)

If you wanted to make it so people can't exploit and take the script when its on the client, move it to the ServerScriptService and write:

Server Script under ServerScriptService

workspace.Part.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		hum.Health = hum.Health + 100
	end
end)

Where "workspace.Part" is the HealBrick

USING REMOTE EVENTS

ServerScript under ServerScriptService

local remote = game:GetService("ReplicatedStorage"):WaitForChild("HealEvent")

remote.OnServerEvent:Connect(function(player)
	player.Character:WaitForChild("Humanoid").Health = player.Character:WaitForChild("Humanoid").Health + 100
end)

Local Script under StarterGui

local player = game.Players.LocalPlayer
local remote = game:GetService("ReplicatedStorage"):WaitForChild("HealEvent")

workspace.Part.Touched:Connect(function(hit)
	if hit.Parent.Name == player.Name then
		remote:FireServer()
	end
end)

Where "workspace.Part" is the HealBrick

2 comments

0

Nothing is happening nothing in output either. Am I missing something?

0

which of these options are you using?

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