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

I have a script which is in a part, when the part is cloned, it is not working, what should I do?

i have used the "Clone" to Clone a part from the "ReplicatedStorage". Inside of the clone is a script:

script.Parent.Touched:connect(function(plr)
	plr.Parent.Humanoid:TakeDamage(10)
end)

And when I touched it..... NOTHING HAPPENED !!!!!

I put the part which was in the "ReplicatedStorage" to the workspace and then it works :D

i still don't know why scripts in parts are cloned or instanced are not work? HELP !!!

P/s: This is a script i use to clone

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:connect(function()
	local try = mouse.Hit
	local p = game.ReplicatedStorage.Part:Clone()
	p.Parent = workspace
	p.CFrame = try + Vector3.new(0,10,0)	
end)

it is in the Starter GUI, not works in the others

5 comments

0

add lua brackets around script

0

can you show us how you're cloning it, and what kind of script it is.

0

lol just do what hasteed said

2

Yeah the issue is you're cloning client sided, you'll need remote events

0

I edited my answer. see now.

1 answer

✓ Accepted answer

You need to detect humanoid with FindFirstChild. and use :Connect the :connect is deprecated.

And for clone disable the script of touch, and after clone active this script.

For first, to clone create a RemoteEvent on ReplicatedStorage, now create ServerScript(Script) in ServerScriptService and put this code:

local event = game.ReplicatedStorage.RemoteEvent -- Location of your event

event.OnServerEvent:Connect(function(player,hit,arg) -- On event, get player and mouse hit position and arg
      if arg == "ClonePart" then -- If argument is clone part then
          local try = hit -- Hit position
          local p = game.ReplicatedStorage.Part:Clone()
          p.Parent = workspace
          p.CFrame = try + Vector3.new(0,10,0)   
      end 
end)

Now on LocalScript put this code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local event = game.ReplicatedStorage.RemoteEvent -- Location of your event

mouse.Button1Down:Connect(function()
    local try = mouse.Hit
    event:FireServer(try,"ClonePart") -- Send mouse position and argument "ClonePart"
end)

Here is a example of touch:

script.Parent.Touched:Connect(function(hit) -- Changed plr to hit.
	if hit.Parent:FindFirstChild("Humanoid") then -- If find humanoid
		hit.Parent.Humanoid:TakeDamage(10)
	end
end)

FindFirstChild:

Returns the first child of the Instance found with the given name. If no child exists with the given name, this function returns nil. If the optional recursive argument is true, this function searches all descendants rather than only the immediate children of the Instance. Use this function if your code cannot guarantee the existence of an object with a given name.

Hope it helped :D

Wiki pages:

FindFirstChild

11 comments

0

You don't need to comment TakeDamage()

0

but it is still not work, what kind of script do I have to put it in?

0

Edited now, and remember to clone with server. not with client.

0

I still don't understand :(

0

You need to clone the part with RemoteEvent or ServerScript(Script).

1

@yHasteeD thats why i wanted to confirm how he was cloning before rushing in with an answer

0

i Edit, pls read

0

.p is deprecated, use .Position

0

thanks for warn again xD

0

Thanks so much :D

0

Wait, don't add the .Position after mouse.hit because mouse.hit is a CFrame value

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