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

My script works in the Roblox Studio, but not in a local server. Why?

Script in workspace:

local humanoid = game.Workspace.Speler.Humanoid
game.Players.PlayerAdded:connect(function(player)
	player = player
end)
humanoid.MaxHealth = 0
humanoid.Health = 0
humanoid.HealthChanged:connect(function(health)
	
	local players = game:GetService("Players")
humanoid.Parent.Head.Touched:connect(function(otherpart)
if otherpart.Name == "Handle" then
	local player = otherpart.Parent.Parent
	local replicatedstorage = game:GetService("ReplicatedStorage")
	local remote = Instance.new("RemoteEvent", replicatedstorage)
	remote:FireClient(player)
	
end
end)
	
end)

LocalScript in startergui:

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

remote.OnClientEvent:connect(function()
	
	local health = game.Workspace.Speler.Humanoid.Health
	game.Workspace.Speler.Humanoid.MaxHealth = 100
	game.Workspace.Speler.Humanoid.Health = 100
end)

What i wanted to do was that if a player damages a humanoid, the damage would only be visible to the client. It did work fine with 1 player in Roblox Studio, but it doesn't work in the localserver.

3 comments

0

The player with the sword does damage it in Roblox Studio, but in the localserver the humanoid get's no damage. That's what i meant

0

who is "Speler"? Speler doesnt exist in real servers

0

Speler is a model in workspace

1 answer

local humanoid = game.Workspace.Speler.Humanoid
game.Players.PlayerAdded:connect(function(player)
	player = player
end)
humanoid.MaxHealth = 0
humanoid.Health = 0
humanoid.HealthChanged:connect(function(health)
	
	local players = game:GetService("Players")
humanoid.Parent.Head.Touched:connect(function(otherpart)
if otherpart.Name == "Handle" then
	local player = otherpart.Parent.Parent.Parent
	print(otherpart.Parent.Parent.Parent.Name)
	local replicatedstorage = game:GetService("ReplicatedStorage")
	local remote = Instance.new("RemoteEvent", replicatedstorage)
	remote:FireClient(player)
	
end
end)
	
end)

At line 13, the part where i wanted to print the otherpart.Parent.Parent.Parent. It gaves in the output 'workspace'. Tht item is in the starterpack, backpack when the game starts. Why does it print workspace?

1 comment

0

I guess the otherPart is a Tool, which happens to be in your Character folder in Workspace when equipped. YourHandle.YourTool.YourCharacter.Workspace.Name == Workspace

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