doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
local boom = Instance.new("Explosion")
local fire = Instance.new("Fire")
local velx = math.abs(script.Parent.Velocity.X)
local velz = math.abs(script.Parent.Velocity.Z)
function onTouched(hit)
if hit.Name == "CarPart" and (velx or velz > 500) then
fire.Parent = hit
boom.Parent = hit
boom.BlastPressure = 500000
boom.BlastRadius = 1
boom.Position = hit.Position
hit:BreakJoints()
end
end
script.Parent.Touched:connect(onTouched)
What this is supposed to do is check if the car is moving a certain speed. If it is, it's supposed to destroy anything named 'CarPart' when it hits it if the car's speed exceeds 500.
But currently it just destroys anything named CarPart, regardless of speed. Help? |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
bump |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
The problem is in this line:
if hit.Name == "CarPart" and (velx or velz > 500) then
Mainly this chunk:
(velx or velz > 500)
The system is going like "Oh, velx isn't nil, I don't need to get into the 'or' part, I'm returning true." cos u didn't do velx > 500, u gotta keep re-typing this stuff for every variable.
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
bump |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
How would I fix that then? I want it to work if the the car is going 500 in the x OR z direction, not just if both are true. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
As I said, type "> 500" for EVERY variable, u did the velz > 500 so I assume u know how to do the same for the velx :P
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
Like this?
if hit.Name == "CarPart" and (velx > 500 or velz > 500) then |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
Because that didn't work |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
It should work, although if I were u I'd probably isolate the X and Z axes in the Vector3 value and then get the magnitude of that instead of checking both values separately.
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
How would I do that? |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
I feel really stupid because nothing that I've tried is working. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
local velocity = Vector3.new(script.Parent.Velocity.X, 0, script.Parent.Velocity.Z)
--Code
if hit.Name == "CarPart" and velocity.Magnitude > 500 then
--Code
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
The reason that doesn't work is because there's a possibility that the velocity could be negative. On the particular map I'm using, the car goes 0, 0, -750. That's why I'm trying to use Absolute value, so no matter what the number is positive. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
.Magnitude is ALWAYS positive.
|
|
fret13103Join Date: 2010-03-15 Post Count: 881 |
workspace.Car:Destroy() |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
Even doing what you said, it's not breaking anything.
local boom = Instance.new("Explosion")
local fire = Instance.new("Fire")
local velocity = Vector3.new(script.Parent.Velocity.X, 0, script.Parent.Velocity.Z)
function onTouched(hit)
if hit.Name == "CarPart" and velocity.Magnitude > 500 then
fire.Parent = hit
boom.Parent = hit
boom.BlastPressure = 500000
boom.BlastRadius = 1
boom.Position = hit.Position
hit:BreakJoints()
end
end
script.Parent.Touched:connect(onTouched) |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
Ah, the breaking part would be hit.Parent:BreakJoints() cos if used on a part I think it only disconnects that 1 part from the parts it's connected to.
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
This is so frustrating, I don't know why it's not working. In other BreakJoints scripts that I use, it's only hit:BreakJoints.
For example, here's a script I use that works.
function onTouched(hit)
if hit.Name == "Part" then
hit:BreakJoints()
elseif hit.Name == "Wedge" then
hit:BreakJoints()
elseif hit.Name == "Smooth Block Model" then
hit:BreakJoints()
elseif hit.Name == "car part" then
hit:BreakJoints()
elseif hit.Name == "Body Part" then
hit:BreakJoints()
elseif hit.Name == "Union" then
hit:BreakJoints()
end
end
connection = script.Parent.Touched:connect(onTouched)
and another one that I use that works:
function touched(hit)
local boom = Instance.new("Explosion")
local fire = Instance.new("Fire")
if hit.Velocity.magnitude > 500 then
fire.Parent = hit
boom.Parent = hit
boom.BlastPressure = 50###### #bo################ 1
boom.Position = hit.Position
end
end
script.Parent.Touched:connect(touched)
The thing is, those are both places inside walls that break cars when they hit it (they're anchored) |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
"Returns: void
Description: Breaks any surface connection with any adjacent part, including Welds and other JointInstances."
Show us a GIF of the problem.
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
hold on working on it |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
Script: ################################################## Proof parts are named right: ################################################## Results: ################################################## |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
Try again ################################################################### |
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
great. It won't let me post Gyazo links |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
Post the Id of it.
|
|
doot_d0otJoin Date: 2012-10-26 Post Count: 1709 |
84dbe7e9fdf909cd98abf35ac1360b88 |
|