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

Why can't i clone a script into a player?

So basically what i want to do is clone a script into the player. I need to know if a player's health is 0, and if it is then set a value in the player to false. I thought the best way to do that was to clone in a script to detect the player's health, but it isn't inserting. There are no errors

Here is my insert script:

game.Players.Playeradded:Connect(function(player)
     local script = game.ReplicatedStorage.Script:Clone()
	for i,v in pairs(game.Workspace:GetChildren())do
		if v.Name == player.Name then
			script.Parent = v
		end
	end
end)

And here is the script i am inserting

while true do
	if script.Parent.Humanoid.Health == 0 then
		for i,v in pairs(game.Players:GetChildren())do
			if script.Parent.Name == v.Name then
				v.Bool.Value = false
			end
		end
	end
	wait(3)
end

There might be a more effective way of doing this, i'm not sure. If there is, please tell me!!!

Thanks!

2 comments

0

There is no need to do this, just put the script you want to insert in the StarterCharacterScripts and it'll work the same

0

oh ok thanks

1 answer

✓ Accepted answer

Put the script you want to insert in StarterCharacterScripts just like What incurszio said. Btw I suggest doing Humanoid.Died event in case the Humanoid's health goes negative (yes negative hp is a thing). So below will be my take on improving the script you want to insert.

script.Parent.Humanoid.Died:Connect(function()
	local chr = script.Parent
	local plr = game.Players:GetPlayerFromCharacter(chr)
	plr.Bool.Value = false
end)

if you wanna know how GetPlayerFromCharacter works, go to https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter

2 comments

0

Its much smaller and in my opinion easier to understand. Let me know if it errors.

0

btw the reason why your insert script didn't work is because PlayerAdded is case sensitive. You said Playeradded when it is PlayerAdded. r/mildlyinfuriating?

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