1 not adding onto a value

Not sure if i should mentioned but the part is touched while the player is in a drive seat of a car

image

Which is why it prints out body as theres a model called body in the car

NOOOOOO. Why didnt you say that earlier

@A5LNX Try this edit and post the console

image

Now you know what you are actually sending. Try to adress the character from there, We can’t since we don’t really know the model of the car and what is where.

Good point. @A5LNX Can you send the file structure of the car. Here is a example a chasis file structure. I want to see where the driver seat is.
asdasd

Exactly the same like the one you just sent

1 Like

Is the seat named the same?
dfjdksfjsdfsdfsfsdf

Yes
(hrfhjhrejfehrfjgrgrg3e3e3e3e)

1 Like

I hate this monstrossity i just did but it should work

local Stage2 = script.Parent
local AttackModeActivated  = game.ServerStorage.AttackModeActivated

Stage2.Touched:Connect(function(otherPart)
	print(otherPart)
	--mazltus wrote this not me. Thats why its so horrible
	if otherPart.Humanoid ~= nil then AttackModeActivated:Fire(otherPart)
	elseif otherPart.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent)
	elseif otherPart.Parent.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent.Parent)
	elseif otherPart.Parent.Parent.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent.Parent.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent.Parent.Parent.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent.Parent.Parent.Parent.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.Parent.Parent.Humanoid ~= nil then AttackModeActivated:Fire(otherPart.Parent.Parent.Parent.Parent.Parent.Parent)
	else
		error("Code broke")
	end
end)

101 reasons why lua should have switch statements

@A5LNX This could work

local Stage2 = script.Parent
local AttackModeActivated  = game.ServerStorage.AttackModeActivated

Stage2.Touched:Connect(function(otherPart)
	print(otherPart)
	
	local function dostuff (character : model)
		print(character.Name)
		AttackModeActivated:Fire(character)
	end
	
	if otherPart.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.Parent.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.Parent.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.Parent.Parent.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent)
	elseif otherPart.Parent.Parent.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent ~= nil then dostuff(otherPart.Parent.Parent.Parent.Parent.Parent.Parent.DriveSeat.Occupant.Parent)
	else
		print("Code broke")
	end
end)
1 Like

didnt print anything out except otherpart, but i did some testing and without the car it works perfectly fine and adds the value, but with the car it starts making problems

otherpart is #Weight in output

Thats wierd can i see a screenshot?

Its the only thing in the output, so there isnt much to send a screenshot about.

1 Like

Found the sollution after some testing on a empty baseplate
This is the whole code:

local AttackModeActivated  = game.ServerStorage.AttackModeActivated

script.Parent.Touched:Connect(function(part)
	pcall(function()
		if part.Parent.Humanoid ~= nil then
			AttackModeActivated:Fire(part.Parent)
		end
	end)
end)

I got no error, but didn’t add value?

What value?

asdasdasdadasdasdsddfsadfsdfsdfsdf

I mean the +1 its meant to add onto the value

1 Like

allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1
this part