#Part with Player Touch detection script giving error "WalkSpeed is not a valid member of Model..."

1 messages · Page 1 of 1 (latest)

queen patrol
#

I made a part that is supposed to detect a player touching it and then running a script using the player that touched it as the object it's doing things with, but it's outputting the error 'WalkSpeed is not a valid member of Model "Workspace.[MyUsername]"' and I'm unsure how to fix this.

#

Here is the portion of my code that detects if a player is touching the part:

    local playerWhoTriggered = game.Players:GetPlayerFromCharacter(otherPart.Parent)
        
    
    
    if playerWhoTriggered then
        local humanoid = playerWhoTriggered.Character
        if humanoid then
            humanoid.WalkSpeed = 0
            humanoid.JumpHeight = 0
            local triggerDialogueLight = script.Parent.Parent
            local targetPosition = triggerDialogueLight.PrimaryPart.CFrame * CFrame.new(0, 0, -5) -- Adjust the offset as needed
            playerWhoTriggered:SetPrimaryPartCFrame(targetPosition)
            local MikaDialogueStep = 1
            if MikaDialogueStep == 1 then --stuff happens here lmao```
flat canyon
#

the actual humanoid is

playerWhoTriggered.Character.Humanoid

not just the player

#

@queen patrol

queen patrol
#

kk, thank you!

flat canyon
#

👍

queen patrol
flat canyon
#

yes

queen patrol
#

kk, thank you!

queen patrol
# flat canyon yes

oof, now I'm getting "PrimaryPart is not a valid member of Part "Workspace.TriggerDialogueLight"" (TriggerDialogueLight is the parent of the script, the part the player is touching)

#

and when I was adding the .Humanoid thing, it wasn't showing it as an option

flat canyon
#

is TriggerDialogueLight a model?

queen patrol
#

it's a part

#

the parent of the script we're editing, the thing that is being touched

#

I'm trying to make it freeze the player for a moment of time, but the way I'm doing it isn't working well

#

oh, hang on, I think I've got it..?

flat canyon
#

you can just the CFrame of that part

#

you don't need to get the primarypart

#

the primarypart comes from models

queen patrol
#

yes, it's working now! now, how would I have the part no-longer detect for players touching it once it's activated, so it only runs once?

flat canyon
#

you can add a latch

#

ill explain

#

just make a variable at the top of the script that is equal to the Boolean "True"

#

and if the script detects if the part has been touched by the player then it will set it as "False"

#

then just check that variable before anything else in you touched function

queen patrol
#

ah, I see, I think I understand what you mean

#

make it a local variable..?

flat canyon
#

yes

queen patrol
#

kk

flat canyon
#

globals aren't really good to work with

queen patrol
#

hm, not entirely working... it just keeps firing the script over and over, even still....

#

even though I set the variable immediately to something else right after the script checks if the variable is the- OHH

#

I see..! when the script is run, it sets the variable to 1

#

so every time you interract with the part, the variable will always be 1

#

hmm...

#

how do I set the variable to 1 only once?

flat canyon
#

I'll show you an example rq

queen patrol
#

okie dokers

flat canyon
#
local variable = true

part.Touched:Connect(function()
  if variable then
    if humanoid then
      variable = false
      --Put code in here
    end
  end
end)
queen patrol
#

but I think that whenever the script is run, it will set variable to true again, no..?

#

cause that's what I have but it's not working...

#

is there a way to check if a variable has been defined?

flat canyon
#

how many times are you running your script?

#

and why?

queen patrol
#

I only want it to happen once. When the player walks through a hallway, there will be an invisible part that when touched will trigger some dialogue, noting the looseness of one of the lights in the ceiling.

flat canyon
#

the script should only be running once

queen patrol
#

it does freeze the player inside the part though once they touch it...

#

it's strange, cause it's definitely running multiple times...

#

perhaps I could use a module..?

#

have the module set the variable first, and have the other script check it then change it

#

that way, it won't reset the value each time it runs

#

would that work?

flat canyon
#

it's not running more than once

#

if you still think that then put a print() statement inside the script

#

at the very first line

queen patrol
#

I'll test it

#

it printed it many times-

#

I put it after it set the variable to 2

#

it's still printing more-

flat canyon
tawny pecanBOT
#

studio** You are now Level 13! **studio

queen patrol
#

oh! i see the problem!

#

i set the variable to 1 INSIDE the if player.character.whatever

#

I put it on line 1, and it's working now

#

thank you for your help!!

flat canyon
#

👍

delicate scarab
#

Character is a model

#

Humanoid is inside this model

#

If the parts been touched, we can safely assume the character is fully loaded

#

local humanoid = playerWhoTriggered.Character:FindFirstChild("Humanoid")