[HELP] Player is able to get typewriting effect more than once

I created a typewriting effect, and i want to make it so a player is only allowed to get the typewriting effect once. But when a player resets their character, they are able to get the typewriting effect again.I tried editing the script (my knowledge in scripting is very limited) and I wasn’t able to achieve what I wanted to achieve. I don’t know where to start, could somebody help? Ive been having this issue for over a week and I dont have any idea on how to resolve it. Here is my script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)

local TriggerPart = workspace:WaitForChild(“TriggerPart1234”)
local Frame = script.Parent.Parent

local typewritingTriggered = {}

function AutoType(textLabel, message)
for i = 1, #message do
textLabel.Text = string.sub(message, 1, i)
task.wait(0.07)
script.Sound:Play()
end
end

TriggerPart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not typewritingTriggered[player] then
typewritingTriggered[player] = true
Frame.Visible = true
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0

	AutoType(script.Parent, "The evil dentist has gone crazy! Let's try and find a way to escape!")
	wait(#"hello hi" * 0.1)  

	Frame.Visible = false
	wait(0)  

	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
end
end)
1 Like

If scripts are in the player gui or character scripts they will be reloaded each time the player’s character is reset.
This would remove the typewriting triggered table reference.

You could place the script in a screengui which has resetonspawn set to false, or place the script in the starter player scripts. This should allow the script to keep it’s variables.

so I just parent the localscript to the screengui? And then set the resetonspawn to false?

I tried that but it just completely messed up the typewriting effect.

He didn’t need help with the typewriting effect itself, but the triggering of the effect. Have you read the post?

1 Like

As for the issue, I don’t know what kind of result you want to achieve, but if this piece of code is in a LocalScript, it’s already running on the player’s side to begin with. I don’t think there is a need for a table at all.

Alternatively, you could set up a boolean variable named dialogueTriggered or something, and check its value in the if statement, and set it to true in the actual code.

1 Like

I want to make it so a player can only get a typewriting effect once
Its a leveled game, and the typewriting effects are meant to give the players tips. But I figured out when a player dies and respawns, they are able to get the typewriting effect again, which would probably annoy the player since they already got it. So once again, my goal is to make it so a player can only get a typewriting effect once.

I have no idea how to script, thats the problem

You don’t have to reparent it, just make sure if it is in a screengui somewhere, that the reset on spawn is false.

1 Like

If you don’t want to put the LocalScript in a ScreenGui, you could Parent it to StarterPlayerScripts, since that way it won’t reset when the character respawns (Although you might need to tweak the code a little). I’m assuming the problem is the script’s parent’s behavior.

What is the original parent of the script?

the localscript is parented to the textlabel

In that case, use the solution that @Wigglyaa recommended.

1 Like

Thank you so much, that worked. Ive been trying to find a solution for my problem for over a week
Again, thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.