#Part with Player Touch detection script giving error "WalkSpeed is not a valid member of Model..."
1 messages · Page 1 of 1 (latest)
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```
the actual humanoid is
playerWhoTriggered.Character.Humanoid
not just the player
@queen patrol
kk, thank you!
👍
so....I replace line 8, just line 8..?
yes
kk, thank you!
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
is TriggerDialogueLight a model?
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..?
you can just the CFrame of that part
you don't need to get the primarypart
the primarypart comes from models
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?
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
yes
kk
globals aren't really good to work with
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?
I'll show you an example rq
okie dokers
local variable = true
part.Touched:Connect(function()
if variable then
if humanoid then
variable = false
--Put code in here
end
end
end)
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?
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.
the script should only be running once
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?
no
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
I'll test it
it printed it many times-
I put it after it set the variable to 2
it's still printing more-
Put the print() statement at the very first line of the script at line 1 and show me your code after that
** You are now Level 13! **
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!!
👍
local humanoid = playerWhoTriggered.Character?
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")