Kill script not functioning

  1. What do you want to achieve? Keep it simple and clear!
    I need the parts involved (ice1, ice2, ice3, ice4, ice5) to deal damage to the player
  2. What is the issue? Include screenshots / videos if possible!
    I have a functioning kill script that for some reason doesn’t work when used in-game
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I couldn’t find any post that could explain what is happening

By the way, there are no errors in the output.
this is the kill script that is inserted into the parts

local Brick = script.Parent

local function PlayerTouched(Part)
	local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
	if Player then
		Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 5
	end
end

Brick.Touched:Connect(PlayerTouched)

this is the other script if you need it

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local rp = game:GetService("ReplicatedStorage")
local ts = game:GetService("TweenService")
local clicked = false



mouse.Button1Down:Connect(function()
	
	if clicked == true then 
		print("anti-spam")
	else
		local Book = player.Character:FindFirstChild("iceBook")
		if Book then 
			if Book.Parent == player.Character then
				local ice1 = rp:FindFirstChild("Ice1"):Clone()
				local ice2 = rp:FindFirstChild("Ice2"):Clone()
				local ice3 = rp:FindFirstChild("Ice3"):Clone()
				local ice4 = rp:FindFirstChild("Ice4"):Clone()
				local ice5 = rp:FindFirstChild("Ring"):Clone()
				local table = {ice1, ice2, ice3, ice4}
				for i, v in pairs(table) do
					v.Parent = workspace
					v.Position = mouse.hit.Position
					local kill = rp:FindFirstChild("Kill"):Clone()
					kill.Parent = v
					v.Name = "ice"..i
				end
	
				
				local kill = rp:FindFirstChild("Kill"):Clone()
				ice5.Parent = workspace
				ice5.Position = ice1.Position + Vector3.new(0, 5, 0)
				kill.Parent = ice5
				local info = TweenInfo.new(
					2, 
					Enum.EasingStyle.Exponential, 
					Enum.EasingDirection.InOut, 
					0, 
					true
				)
				local goals = {
					Size = Vector3.new(75, 8, 8)
				}
				local goals2 = {
					Size = Vector3.new(12, 12, 12)
				}
				local goals3 = {
					Size = Vector3.new(75, 0.1, 75),
					Transparency = 0
				}
				local icetween = ts:Create(ice1, info, goals)
				local icetween2 = ts:Create(ice2, info, goals2)
				local icetween3 = ts:Create(ice3, info, goals2)
				local icetween4 = ts:Create(ice4, info, goals2)
				local icetween5 = ts:Create(ice5, info, goals3)
				icetween:Play()
				icetween2:Play()
				icetween3:Play()
				icetween4:Play()
				wait(0.3)
				icetween5:Play()
				clicked = true
				wait(2)
				ice1:Destroy()
				ice2:Destroy()
				ice3:Destroy()
				ice4:Destroy()
				ice5:Destroy()
				clicked = false
		end
		end
	end
end)

You creating new instances from a local script I think that’s why the script isn’t working how you intended instead make a remote event that will do this attack for you

1 Like

First off, you shouldn’t have this split into two separate scripts. Everything you are trying to do can be accomplished on the server. Also, I think that the player needs to be killed on the server script, not the local script.

1 Like

so you cant create instances normally from a local script?

No. Any instances created on a local script will only exist for that player’s local script. They will not exist for other players.

1 Like

that makes much sense I cant believe i missed this thanks

Well, you can, but it won’t replicate to server, so cloning Instances with ServerScripts would be only visible to you and scripts itself won’t work, so instead you can use RemoteEvent to create killing parts to server.

thanks for the advice, btw do you think the code could be a lot more efficient, this is optional btw

Well, code itself looks pretty decent enough, although there is some things which can be improved, like for example you can not use else condition, you can just do something like that:

local clicked=false
if clicked then return end
clicked=true
-- code below

nice, thanks for the advice, this is my first post however, and I don’t really know how to mark it as solved