Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script for swiming in water?

I made a code but it's not working. There's a place in the studio which has the cancollide property false.I added this script in but it's not working.How can I make it work?It works in Studio but not in Player

function onTouched(part)
	if part.Parent ~= nil then
		local h = part.Parent:findFirstChild("Humanoid")
			if h~=nil then
if  (h.Parent.Torso.Velocity.y < 44) then
h.Parent.Torso.Velocity=Vector3.new(0,h.Parent.Torso.Velocity.y+25,0)
end

			end			
	end
end

script.Parent.Touched:connect(onTouched)

2 comments

0

It should work fine if I read it, but what is it doing - or even: what is it not doing? Also, check the output for any error messages. I just came back from a very long break, so my knowledge might be very rusty.

0

I edited the question

1 answer

What errors do you have?

You need to do some basic debugging before coming here.

Change it to this:

function onTouched(part)
    if part.Parent ~= nil then
        local h = part.Parent:findFirstChild("Humanoid")
            if h~=nil then
print('Humanoid is not nil')
if  (h.Parent.Torso.Velocity.y < 44) then
print('Humanoid Torso velocity is below 44!')
h.Parent.Torso.Velocity=Vector3.new(0,h.Parent.Torso.Velocity.y+25,0)
print('Changed velocity!')
end

            end         
    end
end

script.Parent.Touched:connect(onTouched)

Tell me if it says: 'Humanoid is not nil', 'Humanoid Torso velocity is below 44!', and Changed velocity!

Press F9 while in game, see if there are any errors, and if so write them here. If no errors tell me if it says all of the above statements

2 comments

0

In studio it works, but when I try and see if it works in Roblox Player iI just fall off the map. This is a script not a local script(if that metters)

0

Press F9 In game for the console, click 'Server Scripts' (or similar) and see any errors from your script. Then post them here.

This discussion is preserved as it was. New answers, comments, and votes are closed.