Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

my script says "attempt to index number with changed" in the errors, what is wrong?

Asked by 3 years ago
Edited by theking48989987 3 years ago
game.Workspace.Value.Value.Changed:Connect(function()
    local b = game.Players.LocalPlayer:WaitForChild("Character")
    b.HumanoidRootPart.Anchored = false
    print("Unchored")
end)
0
Maybe it's to do with the random "b" in between ("Character") and HumanoidRootPart? kanyeweasftd 14 — 3y
0
Please use codeblocks, and describe your problem better. This site isn't just "whats wrong fix my code", it's supposed to be a learning experience. matiss112233 258 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

So there are a few things id like to point out

Errors

.1 as kanyeweasftd said, the b between character and hrp.

.2 your trying to index a the number VALUE with Changed, you dont do that, you have to connect .Changed with the instance not the value, do this:

game.Workspace.Value.Changed:Connnect(function()

end)

Tips to make your code look better

Variables

Start using more variables your code is very messy.

Non sense

Why are you waiting for child character? Do this instead

local Players = game:GetService("Players")

local Player = game.Players.LocalPLayer
local Character = Player.Character or Player.CharacterAdded:Wait()

Functions Using local functions there would make your code better, something like this

local function OnValueChange(NewValue)
    --your code
end

Value.Changed:Connect(OnValueChange)

Comments Its always good to make yourself a "comment template"

--// Services


--// Librarys


--// Constants


--// Functions
0
check my answer, there has been a problem dangboxxer2786 4 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

@CaioAlpaca I have Tried 2 scripts first one being


game.Workspace.Value.Changed:Connect(function() local Players = game:GetService("Players") local Player = game.Players.LocalPLayer local Character = Player.Character or Player.CharacterAdded:Wait() Character.HumanoidRootPart.Anchored = false print("Unchored") end)


Second one being


local function OnValueChange(NewValue) local Players = game:GetService("Players") local Player = game.Players.LocalPLayer local Character = Player.Character or Player.CharacterAdded:Wait() Character.HumanoidRootPart.Anchored = false print("Unchored") end game.Workspace.Value.Changed:Connect(OnValueChange)


These Have Both failed

0
dont define the variables inside of the changed function, also any errors in output? CaioAlpaca 342 — 3y
0
nope dangboxxer2786 4 — 3y
0
Also Which Script are you referring to? dangboxxer2786 4 — 3y
0
Is it a local script? CaioAlpaca 342 — 3y

Answer this question