Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago
Edited 6 years ago

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

0
add lua brackets around script DinozCreates 1070 — 6y
0
can you show us how you're cloning it, and what kind of script it is. DinozCreates 1070 — 6y
0
lol just do what hasteed said DinozCreates 1070 — 6y
2
Yeah the issue is you're cloning client sided, you'll need remote events User#24403 69 — 6y
0
I edited my answer. see now. yHasteeD 1819 — 6y

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

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

0
You don't need to comment TakeDamage() User#24403 69 — 6y
0
but it is still not work, what kind of script do I have to put it in? iamthepurpleguy10 15 — 6y
0
Edited now, and remember to clone with server. not with client. yHasteeD 1819 — 6y
0
I still don't understand :( iamthepurpleguy10 15 — 6y
View all comments (7 more)
0
You need to clone the part with RemoteEvent or ServerScript(Script). yHasteeD 1819 — 6y
1
@yHasteeD thats why i wanted to confirm how he was cloning before rushing in with an answer DinozCreates 1070 — 6y
0
i Edit, pls read iamthepurpleguy10 15 — 6y
0
.p is deprecated, use .Position User#24403 69 — 6y
0
thanks for warn again xD yHasteeD 1819 — 6y
0
Thanks so much :D iamthepurpleguy10 15 — 6y
0
Wait, don't add the .Position after mouse.hit because mouse.hit is a CFrame value iamthepurpleguy10 15 — 6y
Ad

Answer this question