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

How to change the value of something when it touches a block? [UN-SOLVED]

Asked by
Uroxus 350 Moderation Voter
10 years ago

So I've made a boat, and in the boats hull theres a BodyForce instance with Y axis set to 26500. Im trying to make this reduce to 13000 when the boat either touches a block or the Terrain, I tried doing terrain in general, but that wouldnt work as Im using roblox water for the sea. I needed it to only work when it touched the Grassy block from default roblox terrain...

I tried making a script that was in the ships hull, but I actually forgot to save the game, so cant provide that. I'm not the best scripter although did watch some of the videos provided by roblox. If someone could give me a push in the right direction, would be much appreciated. Thank you in advance! =)

2 answers

Log in to vote
1
Answered by 10 years ago

Rays are able to return terrain and Parts

Try using this function that I made:

function CastRay(Object,Distance)
    local ray = Ray.new(
        Object.Position,
        Object.CFrame.lookVector*Distance)

local Hit = game.Workspace:FindPartOnRay(ray)
        return Hit
    end

BoatHull = game.Workspace.BoatHull--you dont need this
BoatHull.FrontSurface= "Motor" -- The motor represents where the ray is coming out from(you don't need this part)

while wait() do
--Example:
local Ray = CastRay(BoatHull,1)
    print(Ray)
-------------
    end

If you want it to work like the touch event make sure the distance is set to 1 like I did.

Have any questions about rays or anything else feel free to ask me.

Want to learn about Rays read these pages:

http://wiki.roblox.com/index.php/Raycasting

http://wiki.roblox.com/index.php?title=Scripting_Book/Chapter_17

0
I appreciate your post, But looking at it that just detects if its hit something, not seeing what its hit then decreasing the BodyForce instance, How would that be implemented into this? Usually I would know but quite new to scripting and dont really understand most of that :) Uroxus 350 — 10y
1
It does see whatever the object is hitting in very low distance imitating the touch event and I'm also new to scripting. :P kevinnight45 550 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

I'll give you the start but not the whole thing because you could at least make an effort to make a script.

 game.Workspace.Boatpart.Touched:connect(function(Hit)
   end)

That's what I believe to be the start of that but I could be wrong, I'm a beginner scripter.

0
That's the exact thing I done when I tried my self that didn't work but couldn't provide because the save didn't work. Thanks anyway Uroxus 350 — 10y
0
Yeah..I guess. Sorry man I'd help you out if I could but I don't know that much myself. You also need to add end in there somewhere SprocketSoldier 0 — 10y
0
Hehe, No worries. Thanks for trying :) Uroxus 350 — 10y
0
Wait wait I apologize...have you tried (function(Hit) ? SprocketSoldier 0 — 10y
View all comments (7 more)
0
Nope, what would that do? Uroxus 350 — 10y
0
it would do the same thing as (function(Touched) only i believe touched is wrong its Hit SprocketSoldier 0 — 10y
0
(Touched) and (Hit) wouldn't matter, as they are just arguments. You could name it as (function (jksdhfjksdhf)... end) or something, lol. Redbullusa 1580 — 10y
0
":OnTouch()" is not correct, as it implies that it is a method, not an event. The anonymous function should start like this: game.Workspace.BoatPart.Touched:connect(function (hit) ... end) Redbullusa 1580 — 10y
0
(Hit) shouldn't be spaced from (function .. I think SprocketSoldier 0 — 10y
0
Well, if it worked for you without spaces and it worked for me with a space, then I guess it works both ways. Redbullusa 1580 — 10y
0
;) SprocketSoldier 0 — 10y

Answer this question