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

Script Doesnt Always Change StringValue, Why is that?

i am making a fnaf bot system which it will check which room it is in / what the value is set to and then get a random number between 1 and 20, if it is below or equals the bot level, the bot will move, if it isnt, it will try again, it will choose a random number depending on what room the bot currently is, it will move there and change the string value, hiding the old rig and showing the new one, and once it gets to the door and the door isnt closed it will kick the player out of the game. for some reason the StringValue doesnt always change and it will make the script break, if anyone has an answer please help me.

local poses = game.ReplicatedStorage.CalebPoses
local currentPose = workspace.Poses
local currentRoom = script.Parent.Value
local roomOption = nil
local botLevel = 20
local moveChances = nil
local doorCheck = workspace.RightDoor["RightDoorStatus"]
local attackOption = nil

currentRoom = "Start"
wait(math.random(5,10))
while task.wait(math.random(5,10)) do
	moveChances = math.random(1,20)
	if moveChances <= botLevel then
	if currentRoom == "Start" then
			roomOption = math.random(1,2)
			if roomOption == 1 then
				moveChances = nil
				currentRoom = "Main Party Room"
				poses.CalebMainPartyRoom.Parent = currentPose
				currentPose.CalebIdle.Parent = poses
			end
			if roomOption == 2 then
				moveChances = nil
				currentRoom = "Parts And Service Door"
				poses.CalebNearPartsAndServiceDoor.Parent = currentPose
				currentPose.CalebIdle.Parent = poses
			end
		end
		moveChances = math.random(1,20)
		if moveChances <= botLevel then
		if currentRoom == "Main Party Room" then
			roomOption = math.random(1,5)
			if roomOption == 1 or 2 or 3 then
				moveChances = nil
				currentRoom = "Main Party Room Stare"
				poses.CalebMainPartyRoomStare.Parent = currentPose
				currentPose.CalebMainPartyRoom.Parent = poses
			end
			if roomOption == 4 then
				moveChances = nil
				currentRoom = "Parts And Service Door"
				poses.CalebNearPartsAndServiceDoor.Parent = currentPose
				currentPose.CalebMainPartyRoom.Parent = poses
			end
			if roomOption == 5 then
				moveChances = nil
				currentRoom = "Party Room Hall"
				poses.CalebPartyRoomHall.Parent = currentPose
					currentPose.CalebMainPartyRoom.Parent = poses
				end
			end
			moveChances = math.random(1,20)
			if moveChances <= botLevel then
				if currentRoom == "Parts And Service Door" then
					roomOption = math.random(1,3)
					if roomOption == 1 or 2 then
						moveChances = nil
						currentRoom = "Main Party Room"
						poses.CalebMainPartyRoom.Parent = currentPose
						currentPose.CalebNearPartsAndServiceDoor.Parent = poses
					end
					if roomOption == 3 then
						moveChances = nil
						currentRoom = "Parts And Service"
						poses.CalebPartsAndService.Parent = currentPose
						currentPose.CalebNearPartsAndServiceDoor.Parent = poses
					end
				end
				moveChances = math.random(1,20)
				if moveChances <= botLevel then
					if currentRoom == "Main Party Room Stare" then
						roomOption = math.random(1,4)
						if roomOption == 1 or 2 or 3 then
							moveChances = nil
							currentRoom = "Hallway"
							poses.CalebHallway.Parent = currentPose
							currentPose.CalebMainPartyRoomStare.Parent = poses
						end
						if roomOption == 4 then
							moveChances = nil
							currentRoom = "Main Party Room"
							poses.CalebMainPartyRoom.Parent = currentPose
							currentPose.CalebMainPartyRoomStare.Parent = poses
						end
					end
					moveChances = math.random(1,20)
					if moveChances <= botLevel then
						if currentRoom == "Hallway" then
							roomOption = 1
							if roomOption == 1 then
								moveChances = nil
								currentRoom = "Door"
								poses.CalebDoor.Parent = currentPose
								currentPose.CalebHallway.Parent = poses
							end
							end
								if currentRoom == "Door" then
									wait(7,10)
									if doorCheck == 1 or true then
										moveChances = nil
										currentRoom = "Main Party Room"
										poses.CalebMainPartyRoom.Parent = currentPose
								currentPose.CalebDoor.Parent = poses
							else
									local player = game.Players:GetPlayerFromCharacter()

									player:Kick()
									end
						end
						moveChances = math.random(1,20)
						if moveChances <= botLevel then
							if currentRoom == "Parts And Service" then
								roomOption = 1
								if roomOption == 1 then
									moveChances = nil
									currentRoom = "Main Party Room"
									poses.CalebMainPartyRoom.Parent = currentPose
									currentPose.CalebPartsAndService.Parent = poses
								end
							end
							end
						end
					end
				end 
		end
	end
end



3 comments

0

Is this script parented to a value?

0

no, does that help?

0

i forgot to add .value to that line but ik what u mean

1 answer

✓ Accepted answer

Hello, JmoneyPlayzOfficial!

I see a couple problems in your script:

  1. The currentRoom variable is being set to a value, not mantaining the reference to the object. When you change a variable set this way, it will only change the variable, not the value of the object. To fix you just need to remove .Value from the variable definition and add it to everywhere you are getting the value or setting it

  2. You have some ifs that are evaluating numbers without any condition(eg. if roomOption == 1 or 2 or 3 then) this will make so the if aways considers the condition to be true, as a number, string, or other values(except false) are aways evaluated to true.

  3. Formatting. When reading your script I had some trouble figuring out what was inside what if, I tried to fix it as best as I could.

  4. Line 100 has if [...] or true then, which aways evaluates to true. I'm not sure if you want not to be kicked when testing, but remember to remove it before making the game public.

  5. Line 106 is missing the character argument for :GetPlayerFromCharacter(), so when the execution reaches there, it will throw a error.

Here is the fixed script(except for fixes for #4 and #5).

local poses = game.ReplicatedStorage.CalebPoses
local currentPose = workspace.Poses
local currentRoom = script.Parent
local roomOption = nil
local botLevel = 20
local moveChances = nil
local doorCheck = workspace.RightDoor["RightDoorStatus"]
local attackOption = nil

currentRoom.Value = "Start"
wait(math.random(5,10))
while task.wait(math.random(5,10)) do
    moveChances = math.random(1,20)
    if moveChances <= botLevel then
        if currentRoom.Value == "Start" then
            roomOption = math.random(1,2)
            if roomOption == 1 then
                moveChances = nil
                currentRoom.Value = "Main Party Room"
                poses.CalebMainPartyRoom.Parent = currentPose
                currentPose.CalebIdle.Parent = poses
            end
            if roomOption == 2 then
                moveChances = nil
                currentRoom.Value = "Parts And Service Door"
                poses.CalebNearPartsAndServiceDoor.Parent = currentPose
                currentPose.CalebIdle.Parent = poses
            end
        end
        moveChances = math.random(1,20)
        if moveChances <= botLevel then
            if currentRoom.Value == "Main Party Room" then
                roomOption = math.random(1,5)
                if roomOption == 1 or roomOption == 2 or roomOption == 3 then
                    moveChances = nil
                    currentRoom.Value = "Main Party Room Stare"
                    poses.CalebMainPartyRoomStare.Parent = currentPose
                    currentPose.CalebMainPartyRoom.Parent = poses
                end
                if roomOption == 4 then
                    moveChances = nil
                    currentRoom.Value = "Parts And Service Door"
                    poses.CalebNearPartsAndServiceDoor.Parent = currentPose
                    currentPose.CalebMainPartyRoom.Parent = poses
                end
                if roomOption == 5 then
                    moveChances = nil
                    currentRoom.Value = "Party Room Hall"
                    poses.CalebPartyRoomHall.Parent = currentPose
                    currentPose.CalebMainPartyRoom.Parent = poses
                end
            end
            moveChances = math.random(1,20)
            if moveChances <= botLevel then
                if currentRoom.Value == "Parts And Service Door" then
                    roomOption = math.random(1,3)
                    if roomOption == 1 or roomOption == 2 then
                        moveChances = nil
                        currentRoom.Value = "Main Party Room"
                        poses.CalebMainPartyRoom.Parent = currentPose
                        currentPose.CalebNearPartsAndServiceDoor.Parent = poses
                    end
                    if roomOption == 3 then
                        moveChances = nil
                        currentRoom.Value = "Parts And Service"
                        poses.CalebPartsAndService.Parent = currentPose
                        currentPose.CalebNearPartsAndServiceDoor.Parent = poses
                    end
                end
                moveChances = math.random(1,20)
                if moveChances <= botLevel then
                    if currentRoom.Value == "Main Party Room Stare" then
                        roomOption = math.random(1,4)
                        if roomOption == 1 or roomOption == 2 or roomOption == 3 then
                            moveChances = nil
                            currentRoom.Value = "Hallway"
                            poses.CalebHallway.Parent = currentPose
                            currentPose.CalebMainPartyRoomStare.Parent = poses
                        end
                        if roomOption == 4 then
                            moveChances = nil
                            currentRoom.Value = "Main Party Room"
                            poses.CalebMainPartyRoom.Parent = currentPose
                            currentPose.CalebMainPartyRoomStare.Parent = poses
                        end
                    end
                    moveChances = math.random(1,20)
                    if moveChances <= botLevel then
                        if currentRoom.Value == "Hallway" then
                            roomOption = 1
                            if roomOption == 1 then
                                moveChances = nil
                                currentRoom.Value = "Door"
                                poses.CalebDoor.Parent = currentPose
                                currentPose.CalebHallway.Parent = poses
                            end
                        end
                        if currentRoom.Value == "Door" then
                            wait(7,10)
                            if doorCheck == 1 or true then -- this will aways be true, are you sure?
                                moveChances = nil
                                currentRoom.Value = "Main Party Room"
                                poses.CalebMainPartyRoom.Parent = currentPose
                                currentPose.CalebDoor.Parent = poses
                            else
                                local player = game.Players:GetPlayerFromCharacter() -- missing character definition

                                player:Kick()
                            end
                        end
                        moveChances = math.random(1,20)
                        if moveChances <= botLevel then
                            if currentRoom.Value == "Parts And Service" then
                                roomOption = 1
                                if roomOption == 1 then
                                    moveChances = nil
                                    currentRoom.Value = "Main Party Room"
                                    poses.CalebMainPartyRoom.Parent = currentPose
                                    currentPose.CalebPartsAndService.Parent = poses
                                end
                            end
                        end
                    end
                end
            end 
        end
    end
end




If you still have any questions, please leave a comment and I will reply to it as soon as possible


If this answers your question, please don't forget to mark it as the Accepted Answer.

2 comments

0

THANK YOU! ive spent weeks fixing this and even then there were still bugs, im new to coding so thanks for this!

0

also is line 106 supposed to be something like this local player = game.Players:GetPlayerFromCharacter(character)

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