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
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.
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
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!