So I'm making a horror game where I need to make dialogue and make an NPC move. So I put that in a screengui that is in startergui. It works fine when in single player but in multiplayer, the first user has the only script that works.
The code is all in a server script NOT a local script.
All my code is here:
local player = script.Parent.Parent.Parent
while true do
if workspace.startGame.Value then
break
end
wait()
end
local NPC = workspace.Chaperone
local humanoid = workspace.Chaperone.Humanoid
function anchor()
NPC["Left Arm"].Anchored = true
NPC["Right Arm"].Anchored = true
NPC["Left Leg"].Anchored = true
NPC["Right Leg"].Anchored = true
NPC.Torso.Anchored = true
NPC.Head.Anchored = true
end
function unanchor()
NPC["Left Arm"].Anchored = false
NPC["Right Arm"].Anchored = false
NPC["Left Leg"].Anchored = false
NPC["Right Leg"].Anchored = false
NPC.Torso.Anchored = false
NPC.Head.Anchored = false
end
local label = player.PlayerGui.Messages.TextLabel
local blackout = player.PlayerGui.Messages.Frame
local text = "Chaperone: OH NO!!! The bus broke down!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
for count = 1,2 do
NPC.Humanoid:MoveTo(Vector3.new(0,0,10))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(10,0,10))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(10,0,0))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(0,0,0))
NPC.Humanoid.MoveToFinished:Wait()
end
wait(2)
text = "Chaperone: What are we going to do? What are we going to do? What are we going to do?"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
for count = 1,3 do
NPC.Humanoid:MoveTo(Vector3.new(0,0,10))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(10,0,10))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(10,0,0))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(0,0,0))
NPC.Humanoid.MoveToFinished:Wait()
end
wait(0.5)
anchor()
wait(1)
label.Text = ""
text = "Chaperone: We should find some wood around here to build a shelter until we are rescued. You might also find some useful items!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
local script1 = workspace.wood.Script
local wood = workspace.wood
wood.CanCollide = true
wood.Transparency = 0
script1.Disabled = false
script1 = workspace.wood1.Script
wood = workspace.wood1
wood.CanCollide = true
wood.Transparency = 0
script1.Disabled = false
script1 = workspace.wood2.Script
wood = workspace.wood2
wood.CanCollide = true
wood.Transparency = 0
script1.Disabled = false
script1 = workspace.wood3.Script
wood = workspace.wood3
wood.CanCollide = true
wood.Transparency = 0
script1.Disabled = false
script1 = workspace.wood4.Script
wood = workspace.wood4
wood.CanCollide = true
wood.Transparency = 0
script1.Disabled = false
workspace.woodBarrior.CanCollide = false
workspace.woodBarrior1.CanCollide = false
workspace.woodBarrior:Destroy()
workspace.woodBarrior1:Destroy()
unanchor()
NPC.Humanoid:MoveTo(Vector3.new(40.57, 0.5, 44.917))
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(Vector3.new(40.57, 0.5, 39.917))
NPC.Humanoid.MoveToFinished:Wait()
wait(0.5)
anchor()
local collecting = workspace.Collecting
collecting.Value = true
while collecting.Value do
local value = workspace.WoodCollected
label.Text = "Wood Collected: " .. workspace.WoodCollected.Value
if workspace.WoodCollected.Value==5 then
collecting.Value = false
end
wait()
end
workspace.WoodCollected.Value=5
wait(1)
text = "Chaperone: Nice work! Now we have somewhere to stay! Luckily, we can use the bus seats as beds. Now you can keep exploring for a little longer!"
local cabin = game.ReplicatedStorage.Cabin:Clone()
cabin.Parent = workspace
player.PlayerGui.WoodCollected.TextLabel.Text = ""
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(30)
text = "Chaperone: QUICK! Get into the cabin! It's starting to rain and it's getting dark!!"
game.Lighting.TimeOfDay = "20:00:00"
wait(5)
local damageareas = game.ReplicatedStorage.raindamageareas:Clone()
damageareas.Parent = workspace
local rain = game.ReplicatedStorage.rain:Clone()
rain.Parent = workspace
local rain1 = game.ReplicatedStorage.rain1:Clone()
rain1.Parent = workspace
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(15)
local text = "Chaperone: OK, I think we should go to sleep now..."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
for b = 1,100 do
blackout.BackgroundTransparency = blackout.BackgroundTransparency - b/100
wait()
end
wait(3)
game.Lighting.TimeOfDay = "10:00:00"
local rain = workspace.rain:GetChildren()
for c = 1, #rain do
rain[c]:Destroy()
end
for e = 1,100 do
blackout.BackgroundTransparency = blackout.BackgroundTransparency + e/100
wait()
end
local rain1 = workspace.raindamageareas:GetChildren()
for c = 1, #rain1 do
rain1[c]:Destroy()
end
local text="Chaperone: The rescue team should be coming later today or tomorrow. We just have to wait and see..."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(10)
label.Text = ""
label.BackgroundTransparency = 0.5
wait(60)
local text = "Chaperone: It's almost night-time. You should head back to the cabin."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(10)
game.Lighting.TimeOfDay = "20:00:00"
wait(10)
local text = "Chaperone: Uh-oh! The cabin is about to collapse!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(3)
local cabinchildren = workspace.Cabin:GetChildren()
for g=1, #cabinchildren do
cabinchildren[g]:Destroy()
end
local collapsed = game.ReplicatedStorage.collapsed:Clone()
collapsed.Parent = workspace
local demon = game.ReplicatedStorage.Demon
demon.Parent = workspace
local text = "Chaperone: RUN RUN RUN RUN!!!!!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(30)
demon:Destroy()
local text = "Chaperone: Phew! That was a close one. It should be gone now."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(2)
local text = "Chaperone: I think I saw a cave somewhere near here. Maybe we can take shelter there?"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(20)
text = "Chaperone: Take shelter in the cave! It's starting to rain!"
wait(5)
game.ReplicatedStorage.cabindamagearea:Clone().Parent = workspace
local damageareas = game.ReplicatedStorage.raindamageareas:Clone()
damageareas.Parent = workspace
local rain = game.ReplicatedStorage.rain:Clone()
rain.Parent = workspace
local rain1 = game.ReplicatedStorage.rain1:Clone()
rain1.Parent = workspace
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(20)
for n = 1,100 do
blackout.BackgroundTransparency = blackout.BackgroundTransparency - n/100
wait()
end
target = CFrame.new(62.11, -15.158, 4427.591) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
--Make sure the character exists and its torso exists
if player.Character and player.Character:FindFirstChild("Torso") then
--add an offset of 5 for each character
player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
end
end
for m = 1,100 do
blackout.BackgroundTransparency = blackout.BackgroundTransparency + m/100
wait()
end
workspace.SpawnLocation:Destroy()
local spawnpoint = game.ReplicatedStorage.SpawnLocation:Clone()
spawnpoint.Parent = workspace
text = "Chaperone: Oh no! Where are we? NOOO! It looks like the cave collapsed! We have to get out of the cave! Quick!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(2)
local demon1 = workspace.Demon1
demon1.Name = "Demon"
for timeLeft = 1,60 do
label.Text="Get out of the cave! (" .. 60-timeLeft .. ")"
wait(1)
end
local caveDetector = game.ReplicatedStorage.caveDetector:Clone()
caveDetector.Parent = workspace
workspace.SpawnLocation:Destroy()
local spawnlocation1 = game.ReplicatedStorage.SpawnLocation1:Clone()
spawnlocation1.Parent = workspace
text = "Chaperone: We got out! That was hard..."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(3)
wait(1)
text = "Chaperone: AAAAAAH!!! IT'S THE DEMON!! "
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(1)
workspace.startEnding.Value = true
game.ReplicatedFirst.EndPart:Clone().Parent = workspace
game.ReplicatedFirst.FocusPart:Clone().Parent = workspace
--game.ReplicatedFirst.CameraScript:Clone().Parent = player.PlayerScripts
text = "Demon: I have now trapped you!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(3)
text = "Demon: You now have nowhere to go..."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(3)
text = "Demon: I now can finally kill you!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(3)
text = "..."
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait(1)
end
wait(1)
game.ReplicatedFirst.EndPart1:Clone().Parent = workspace
game.ReplicatedFirst.FocusPart1:Clone().Parent = workspace
game.ReplicatedStorage["Police Officer."]:Clone().Parent = workspace
game.ReplicatedStorage["Police Officer.1"]:Clone().Parent = workspace
text = "Police: HALT!!!!"
workspace.police.Value = true
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(1)
text = "Demon: UH-OH!!!"
for i = 1, #text do
label.Text = string.sub(text,1,i)
wait()
end
wait(10)
label.Text = "You Win!!"
script.Parent.Frame.BackgroundTransparency = 1
