[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(“TriggerPart”)
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

Make a server script and put it in ServerScriptService

local Event = game.ReplicatedStorage.EVENT --Make an event and put it in ReplicatedStorage and change 'EVENT' to the name of the event

game:GetService('Players').PlayerAdded:Connect(function(plr)

      Event:FireClient(plr) --Fires the event to the client (This will only happen once....when the player joins the server)

end)

Then, you just need to simply add the Event into your local script.

local Event = game.ReplicatedStorage.EVENT --Change 'EVENT' to the name of the event

Event.OnClientEvent:Connect(function() --Happens when the event is fired (it will only happen once...when the player joins the server


PUT YOUR CODE HERE!!!

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)

There might be a few spelling mistakes here, so let me know if it works

1 Like

Alright, thank you, ill try that and ill get back to you

Alright, so I adjusted my scripts and now it doesn’t work. here is what I ended up with (also how do I get that script text for whenever I type a script on devforum)

ServerScriptService script:

local Event = game.ReplicatedStorage.StupidEvent --Make an event and put it in ReplicatedStorage and change ‘EVENT’ to the name of the event

game:GetService(‘Players’).PlayerAdded:Connect(function(plr)

Event:FireClient(plr) --Fires the event to the client (This will only happen once....when the player joins the server)

end)

LocalScript:

local Event = game.ReplicatedStorage.StupidEvent

Event.OnClientEvent:Connect(function()

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

local TriggerPart = workspace:WaitForChild(“TriggerPart123”)
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)

Sup, you do this to get the script text:
image

Could you check the output of your game (Press F9) and send me a screenshot?

Sure, heres what I’m getting

Hmm, Replace line 7 with:

local Humanoid = Character:WaitForChild("Humanoid")

And replace line 9 with:
local TriggerPart = workspace:WaitForChild("TriggerPart123")

Thats what I already have on line 7

local Humanoid = Character:WaitForChild(“Humanoid”)

And thats also what I have for line 9

The quotes you put on that line are a different unicode character. Copy them two lines and it should work perfectly.

You had: “Humanoid”, whereas, it should’ve been: "Humanoid"

I replaced those two lines of code, and this is what i’m getting in the output now:

That will be pretty easy to fix. Can you send me the local script like this:

example 
1 Like

Sure, sorry for the late response:

local Event = game.ReplicatedStorage.StupidEvent

Event.OnClientEvent:Connect(function()

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


    local TriggerPart = workspace:WaitForChild("TriggerPart123")
    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)

Hey sorry for the late reply

You forgot to add another ‘end)’

This should work:

local Event = game.ReplicatedStorage.StupidEvent

Event.OnClientEvent:Connect(function()

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


    local TriggerPart = workspace:WaitForChild("TriggerPart123")
    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)
end)
1 Like

I was able to figure it out in the meantime, but thank you so much for trying to help, I appreciate it

Np, do you mind marking my post as the solution?

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