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)
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.
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.
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.
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.