Speedboat isn't going forward

  • What are you attempting to achieve? - I’m trying to achieve my speedboat going forwards when the player count is equal to 1
  • What is the issue? (Keep it simple and clear - When I enter the boat, it does register as 1 but then the speedboat doesn’t go forward it still prints as ‘Not enough players on boat’
  • What solutions have you tried so far? - I have tried solutions I can think of such as changing the functions but it still doesn’t seem to work.

Here is what my current script looks like (part where it checks for playercount and then makes it go forward)

if PlayerCount.Value > 1 then
	for i = 0,-100,-.1 do
	script.Parent:TranslateBy(Vector3.new(i,0,0)) --Stuff for boat to go forward
	end
else
	if PlayerCount.Value < 1 then
		print "Not enough people on boat!"
	end
end

Thanks!

So when PlayerCount.Value == 1 then ?

if the Player.Count.Value == 1 then it should trigger the boat to go forwards.

but the code states >1 not ==1

Even if I do change it to

if PlayerCount.Value == 1 then

It still gives me the error of “Not enough people on boat!”

Which is making me puzzled onto why this is happening.

I suggest you just try the logic of that with prints to make sure you have the code right.
Make the test code as simple as possible.

1 Like

Try just replacing the first line:

if PlayerCount.Value > 1 then

With this line:

if PlayerCount.Value >= 1 then

I would also see if your code is detecting players in the first place. Just print what the value is at the place it is changed, and if it does not print, that will need to be fixed.

1 Like

Whats happening here is this. A guy hops on your boat, and this function fires.

if PlayerCount.Value > 1 then
-- this isnt going to fire, since theres only one guy, and meet this if statement there needs to be 2+ people (> means over one)

change this to

if PlayerCount.Value >= 1 then
-- the >= symbol means over OR equal to, not just one or the other. Unlike the previous statement, this one will be meet the requirement when one guy gets on the boat.

About this:

else 
      if PlayerCount.Value < 1 then print "Not enough people on boat!" 
end 
end
-- this branch is entirely useless, since the function only is called when 1+ people enter the boat, but this else branch only runs if there are none. See the loophole? 

Instead, change your code to this.



if PlayerCount.Value >= 1 then  -- if one or more people enter the boat, move forward.
for i = 0,-100,-.1 do 
script.Parent:TranslateBy(Vector3.new(i,0,0)) 
end 
end

EDIT: If you only want the boat to move when

2 Likes

I’d try making sure that the PlayerCount is being set properly through print() functions, and I would try changing your script to this:

local minPlayerCount = 1

if PlayerCount.Value >= minPlayerCount then
	print("There are enough people on the boat! The number of people on the boat is " .. PlayerCount.Value .. ".") --This part is just to make sure that the 'if' condition is being met.
	for i = 0,-100,-.1 do
		script.Parent:TranslateBy(Vector3.new(i,0,0)) --Stuff for boat to go forward
	end
elseif PlayerCount.Value < minPlayerCount then
		print "Not enough people on boat! There are " .. PlayerCount.Value .. " people on the boat." --If the script seems to think that there are not enough players on the boat, it will specify how many players it thinks are on the boat.
	end
end

If it prints that there are enough people on the boat and it still refuses to move, it is most likely there is some mistake where you try to make the boat move. By the way having the minimum player count in a variable is not necessary, I just did so so that it is easy to change the value in the future if you ever feel the need.

Note: If my post or any of the posts above solved your problem, mark it as the Solution. I hope I helped!

1 Like