#My script starts lying to me after a few seconds

1 messages · Page 1 of 1 (latest)

sharp bronze
#

It works fine for a few seconds but then begins saying that the player character doesn't have a cursor script as a descendant. I don't know why it does this. I don't have any sort of timers set up or anything, nor do I have anything set to change the hasCursor boolean after a certain amount of clicks.

#

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local spawnThorne_RE = game.ReplicatedStorage.Brickmin:WaitForChild("spawnThorne") 
local getMouseDotPos_RE = game.StarterPlayer.StarterPlayerScripts:WaitForChild("getMouseDotPos")

local hasCursor = false
local spawnPos;

getMouseDotPos_RE.Event:Connect(function(mouseDotPos)
    spawnPos = mouseDotPos
end)

userInput.InputBegan:Connect(function(input, gameprocessed)
    if gameprocessed then return end
    
    for i,v in pairs(char:GetDescendants()) do
        if v.Name == "Cursor" then
            hasCursor = true
        else 
            hasCursor = false
        end
    end
    
    print(hasCursor)
    
    if hasCursor and input.KeyCode == Enum.KeyCode.Four then
            --print(player.Name .. " pressed 4")
            spawnThorne_RE:FireServer(spawnPos)
            --print(`{player.Name} wants to spawn a Thorn.`)        
        
    end
end)```
#

Once the player gets a cursor, the hasCursor becomes true. However, it should stay true indefinitely, since as of now, the player has no way of getting the rid of the cursor unless they reset.

nocturne bisonBOT
#

studio** You are now Level 9! **studio

sterile tree
#

Here's a fixed version

local hasCursor = false
for _, descendant in character:GetDescendants() do
  if descendant.Name == "Cursor" then
    hasCursor = true
    break
  end
end
sharp bronze
knotty aspen
#

yo uh, I have a question

wooden wave
knotty aspen
#

mty text wasn't loading

knotty aspen
sharp bronze
#

You use `

knotty aspen
#

ah ok ty

#

e

sharp bronze
#

nvm figured out i could js do this using tables

#

and getting the amount of objects in a table to use as a psuedo boolean

sharp bronze
#

nvm it dont work lmfao