Typewriting effect occurs for all players

I created a typewriting effect, and its supposed to only work locally, but when I tested it, It worked for both players. 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("TriggerPart1") 
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, "test test test test")
		wait(#"hello hi" * 0.1)  

		Frame.Visible = false
		wait(0)  

		Humanoid.WalkSpeed = 16
		Humanoid.JumpPower = 50
	end
end)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local TriggerPart = workspace:WaitForChild("TriggerPart1") 
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] and player == Player then
		typewritingTriggered[player] = true
		Frame.Visible = true
		Humanoid.WalkSpeed = 0
		Humanoid.JumpPower = 0

		AutoType(script.Parent, "test test test test")
		wait(#"hello hi" * 0.1)  

		Frame.Visible = false
		wait(0)  

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

try that

man you could just use RemoteEvent and type it on player’s local script

after touched, remoteevent send to the client and doing some stuff

i have no idea how to script thats why im asking for help

Script on your part

Part.Touched:Connect(function(hit)
local player = game.Players:getplayerfromcharacter(hit.Parent)
RemoteEvent:FireClient(player)
end)

Script on player client

RemoteEvent.OnClientEvent:Connect()
-- your ahh type writing stuff
end)

And… please setup the variables by yourself. I’m a bit tired right now.

1 Like

Ok so I adjusted the process a little bit, I created a remote event named TypewritingEvent, and I created a server side script and adjusted the local script, it works for the first typewriting effect, but I dont know how to make it work for the others, Here is my serverside script (handles the 1st typewriting effect):

local TriggerPart = workspace:WaitForChild("TriggerPart1")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TypewritingEvent = ReplicatedStorage:WaitForChild("TypewritingEvent")

TriggerPart.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		TypewritingEvent:FireClient(player, "test test test test")
	end
end)

And here is my LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TypewritingEvent = ReplicatedStorage:WaitForChild("TypewritingEvent")

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

local Frame = script.Parent.Parent

local typewritingTriggered = {}

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

TypewritingEvent.OnClientEvent:Connect(function(message)
	if not typewritingTriggered[Player] then
		typewritingTriggered[Player] = true
		Frame.Visible = true
		Humanoid.WalkSpeed = 0
		Humanoid.JumpPower = 0

		AutoType(script.Parent, message)
		wait(#"hello hi" * 0.1)

		Frame.Visible = false
		wait(0)

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

Could you help me adjust the scripts to make it work for each typewriting effect

AutoType(script.Parent, "hello im from saudi arabia")

wait(#"hello hi" * 1) -- wtf is this???

AutoType(script.Parent, "im here to take your 20 million barrel of oil")

you could do right that.

I tried that before and it didn’t work, in the server script right ?

can you show me the video? and also can you just write wait(1) instead of idk what kind of thing?

Here are some screenshots
1st Server script:


2nd Local Script in the typewriting effect

Yo nevermind, I think i problem-solved
thanks for helpin