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

[SOLVED] How do you get server script to work when its parent is cloned?

Asked by 4 years ago
Edited 4 years ago

I am having an issue when you throw the object, it clones and when it hits a player, it is supposed to damage them. It is a .Touched() function. Any Help?

The Code:

local part = script.Parent

local damage = 10

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid") 
        humanoid:TakeDamage(damage)
    end
end)
0
Buddy, we need the code; any possible errors that have been thrown too. You can't leave us with an RBXScriptSignal. Ziffixture 6913 — 4y
0
I will put the code in UraniumBanana5 33 — 4y
0
No errors. I have tried to get it to print when it's touched, but nothing UraniumBanana5 33 — 4y
0
Firstly, a signal should never be encapsulated in an infinite loop, you just need the one my friend. Secondly, you can pre-allocate the Humanoid instead of using :FindFirstChild() twice. Ziffixture 6913 — 4y
View all comments (5 more)
0
Sorry about the loop. There was no loop before. I left that in by accident UraniumBanana5 33 — 4y
0
It's always best to use the Debris Service when handling projectiles. You can't allow multiple Instances to remain in the workspace forever, otherwise you'll induce unwanted lag. Furthermore, you'd need to either disconnect the signal, or destroy the projectile upon contact, as the signal will likely fire more than once, ultimately dealing more damage than intended. Ziffixture 6913 — 4y
0
The main script clones it, disables the script inside the part, puts the part in the folder and deletes the part after 2 seconds of being cloned UraniumBanana5 33 — 4y
0
The program needs to remain active in order for the code to execute. Ziffixture 6913 — 4y
0
I'm not sure what you mean by that UraniumBanana5 33 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I was using the clone script through the client, so I used a remote event and switched scripts over. I used the client for animations and I used the remote event to get the mouse position.

Ad

Answer this question