Alright, so I'm making a game about magic and stuff. I'm trying to make a script to summon a rock and throw it to a specific place, and when it hits something it explodes, but it won't explode. The script to make it explode isn't faulty. I copied and pasted it into another part, and it worked then when I touched it. I even filed down the script into just the exploding section (the script damages and whatever it touches needs to have certain properties) and it still doesn't work. This is the compressed version:
Par =script.Parent script.Parent.Touched:connect(function(h) Par.Transparency=1 Par.Anchored= true Par.Sound:Play() Par.ParticleEmitter.Enabled = true wait(0.1) Par.ParticleEmitter.Enabled = false wait(2) Par:Destroy() end)
The rock in question is supposed to be cloned from ReplicatedStorage and the clone is parented to workspace. I set it to ReplicatedStorage instead of ServerStorage because if I tried ServerStorage it said it wasn't a member of ServerStorage, and when I checked sure enough it wasn't there. But, in previous scripts I made, ServerStorage has always worked and it never showed ServerStorage parenting anything during tests. I copied everything into another game and the same error occurs. I tried cloning an unedited part using [game.ServerStorage.Part:Clone().Parent = workspace] in both places and it worked fine, so I don't understand why the rock doesn't work. I don't think it's replicated storage, but rather the children of the rock.
Sound (plays when it explodes)
Attack (the script that makes it explode, but filed down)
Attack (the original script that I have disabled for debugging)
Caster (object value with a value of the, you guessed, caster so that the rock doesn't explode
when it hits a child of the caster)
Damage (value of damage it deals, originally set to 15)
Magic (indicator that it is a magic part, as two magic parts colliding reduces the part with the
higher damage value to be reduced by the weaker value, while the weaker is destroyed)
ParticleEmitter (is enabled during explosion)
Force (BodyPosition that sets the rock's target)
I don't see how the scripts do not work and it is extremely frustrating. Please help.
EDIT: I have just ran a test that proves that ReplicatedStorage is at fault here. I took the rock from RS, put it in workspace, set a target for the rock and ran it. The rock functioned perfectly, exploding on hit with the target in the manner that I want it to. The problem is getting the rock to be cloned form ServerStorage instead of RS, but SS still does not want to accept the rock as its member. How can I make it so that it will?
EDIT2: The process to summon the rock comes from a local script set in a gear. I'm going to copy the contents of it and paste it into another script, that isn't a local script. It is local because i have
tool = script.Parent playerMouse = game.Players.LocalPlayer:getMouse()
but i will remove this and use my Activated:connect(function()'s parameter instead of playerMouse. Maybe that's why it doesn't copy from ServerStorage.
EDIT3: Eureka! That's what I had to do. Thanks to the one guy who tried.
ok so i found a solution:
make sure that anchored and cancollide are enabled. then put this script.
Par = script.Parent script.Parent.Touched:Connect(function(onhit) -- this makes it functions when something touches it if onhit.Parent then Par.Transparency=1 Par.Anchored= true Par.Sound:Play(onhit) Par.ParticleEmitter.Enabled = true wait(0.1) Par.ParticleEmitter.Enabled = false wait(2) Par:Destroy(onhit) end end)