here is the script in the part that I want removed if it come in contact with another part
--[[ filler XP--]] function touch(hit) hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -50
just for notice I want the part removed not the script, and I want the part to came back after 3 secs
If that is your entire script, let me give you a few tips:
You must Connect
your function in order for it to be triggered whenever a part is Touched
.
Before changing the Health of a Humanoid, you should make sure the part touching belongs to a player's character. You can do this by calling GetPlayerFromCharacter
on the Players service.
In order to make the part disappear for 3 seconds, you should move it to ServerStorage
and then back to workspace
.
local players = game:GetService("Players") local storage = game:GetService("ServerStoarage") local part = script.Parent local function Touch(hit) local character = hit.Parent local player = players:GetPlayerFromCharacter(character) if player then character.Humanoid.Health = character.Humanoid.Health - 50 part.Parent = storage wait(3) part.Parent = workspace end end part.Touched:Connect(touch)
Instead of using :Destroy() or something like that, you can parent the part to nil, then after three seconds it parents back to whatever object it was originally parented to.
(Your formatting of the script was hard to read so this was what i thought it was trying to be) ((I'm also not a very good scripter so don't get mad if this is bad)
whatever = script.Parent.Parent function touch(hit) hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 50 script.Parent.Parent = nil wait(3) script.Parent.Parent = whatever end