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

My localscript is not a valid member of DataModel, how do I fix this? [SOLVED]

This LocalScript is located in StarterGui.ScreenGui.ImageButton.Frame.TextButton

script.Parent.MouseButton1Click:Connect(function()
		game:WaitForChild("EmoteFreeze", 2)
local emotelimit = workspace.Parent.EmoteFreeze
	if emotelimit.Disabled == false then
		emotelimit.Disabled = true
	else
		emotelimit.Disabled = false
	end
	wait(0.1)
	emotelimit.Disabled = false
	
end)

The script above activates this LocalScript, location in StarterCharacterScripts

local human = script.Parent.Humanoid

human.AutoRotate = false
human.WalkSpeed = 0
human.JumpPower = 0

wait(3)
human.AutoRotate = true
human.WalkSpeed = 12
human.JumpPower = 20

It basically freezes my character so it cannot move or rotate, and when I clicked the button it tells me this in the output "EmoteFreeze is not a valid member of DataModel"

And this is the working script, but I think it only activates for me:

script.Parent.MouseButton1Click:Connect(function()
		game:WaitForChild("EmoteFreeze", 2)
local emotelimit = workspace.Aldovy.EmoteFreeze
	if emotelimit.Disabled == false then
		emotelimit.Disabled = true
	else
		emotelimit.Disabled = false
	end
	wait(0.1)
	emotelimit.Disabled = false
	
end)

So I need to change "workspace.Parent.EmoteFreeze" into "workspace.Aldovy.EmoteFreeze" with my name in it? I don't think that will work with other player in the server. please someone, help me :]

And here is the first localscript i made, located in the button

game.workspace:WaitForChild("Humanoid", 1)
local human = game.workspace.Aldovy.Humanoid
script.Parent.MouseButton1Click:Connect(function()
		if human.AutoRotate == true then
			human.AutoRotate = false
		else
			human.AutoRotate = true
		end
		if human.WalkSpeed == 10 then
			human.WalkSpeed = 0
		else
			human.WalkSpeed = 10
		end
		if human.JumpPower == 20 then
			human.JumpPower = 0
		else
			human.JumpPower = 20
		end
		wait(3)
		human.AutoRotate = true
		human.WalkSpeed = 10
		human.JumpPower = 20
		
	end)

4 comments

0

why not just do what the "EmoteFreeze" script is doing inside of the buttons script? i feel like you're over complicating a simple task.

0

I already did that, same output

0

I'm sorry, not exactly the same output. It tells me "Humanoid is not a valid member of DataModel"

0

Update: Posted the localscript inside the button

1 answer

✓ Accepted answer

The descendants of StarterCharacterScripts are parented to the Player's character every time it is loaded. Characters are located inside Workspace. You're waiting for a maximum for 2 seconds for the EmoteFreeze LocalScript to appear directly inside Workspace. Instead, it is going to appear inside the Player's character; after 2 seconds, the script will throw an error. So how do we get the character?

When you're working with LocalScripts, you can get the local player with Players.LocalPlayer. This property is assigned to the Player that belongs to the client. Player.Character is assigned to the character of the Player. If the character does not exist, this property will be nil.

With this in mind, let's fix your script:

local players = game:GetService("Players")
local local_player = players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	-- Check if the character doesn't exist.
	local character = local_player.Character
	if not character then
		return
	end
	-- Check if the EmoteFreeze LocalScript hasn't loaded.
	local emote_freeze = character:FindFirstChild("EmoteFreeze")
	if not emote_freeze then
		return
	end
	-- not true <--> false, not false <--> true
	emote_freeze.Disabled = not emote_freeze.Disabled
	wait(0.1)
	emote_freeze.Disabled = false
end)

I hope that this helped!

4 comments

0

It works! Thank you very much for spending your time making this script for me! :)

0

I was about to reply with an error message. But i found a little typo there, you typed PLayer instead of Player, haha

0

No worries! Please accept this answer and/or add "[SOLVED]" to your title for others who may come across a similar issue. :)

0

Fixed :p

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