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
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: