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

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

Asked by
Aldovy 2
5 years ago
Edited 5 years ago

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)
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. DinozCreates 1070 — 5y
0
I already did that, same output Aldovy 2 — 5y
0
I'm sorry, not exactly the same output. It tells me "Humanoid is not a valid member of DataModel" Aldovy 2 — 5y
0
Update: Posted the localscript inside the button Aldovy 2 — 5y

1 answer

Log in to vote
1
Answered by
BenSBk 781 Moderation Voter
5 years ago
Edited 5 years ago

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!

0
It works! Thank you very much for spending your time making this script for me! :) Aldovy 2 — 5y
0
I was about to reply with an error message. But i found a little typo there, you typed PLayer instead of Player, haha Aldovy 2 — 5y
0
No worries! Please accept this answer and/or add "[SOLVED]" to your title for others who may come across a similar issue. :) BenSBk 781 — 5y
0
Fixed :p BenSBk 781 — 5y
Ad

Answer this question