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

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

game.Workspace.Value.Value.Changed:Connect(function()
	local b = game.Players.LocalPlayer:WaitForChild("Character")
	b.HumanoidRootPart.Anchored = false
	print("Unchored")
end)

2 comments

0

Maybe it's to do with the random "b" in between ("Character") and HumanoidRootPart?

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.

2 answers

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

1 comment

0

check my answer, there has been a problem

@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

4 comments

0

dont define the variables inside of the changed function, also any errors in output?

0

nope

0

Also Which Script are you referring to?

0

Is it a local script?

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