I am trying to make a game that has buildings that you teleport to (fake exterior), and when you go to the door to teleport to them you have a transition that is basically a fade in to black and then the black fades out. I tried to use a server-client based RemoteEvent, but it seems to have absolutely no effect even though I know it is being fired (and unusually it is also fired when the server first starts.) Can somebody help me out with this?
My server-script:
-- Teleport function --
for i, doorTouched in pairs(Server.teleportDoor:GetDescendants()) do
if doorTouched:IsA("Part") then
doorTouched.Touched:Connect(function(plr)
local hp = plr.Parent:FindFirstChild("HumanoidRootPart")
if hp then
local localplr = game.Players:GetPlayerFromCharacter(plr.Parent)
Server.remoteEvent:FindFirstChild("teleTrans"):FireClient(localplr) -- This is supposed to trigger a transition, but it has no effect.
hp.CFrame = CFrame.new(doorTouched.Config.Location.Value)
end
end)
end
end
Here is my localscript which handles the transition too:
-- Teleportation Handler --
local function transStart(Gui)
local transition = Gui:FindFirstChild("TransitionFrame")
local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.Out)
local maxTrans = {
Transparency = 1,
BackgroundColor3 = Color3.new(1,1,1)
}
local tween = Client.tweenService:Create(transition,info,maxTrans)
transition.Visible = false
end
local function transMove(player)
local playerGui = player.PlayerGui
local transition = playerGui:FindFirstChild("TransitionFrame")
local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
local maxTrans = {
Transparency = 0,
BackgroundColor3 = Color3.new(1,1,1)
}
local tween = Client.tweenService:Create(transition,info,maxTrans)
wait(2)
transStart(playerGui)
end
Client.remoteEvents:FindFirstChild("teleTrans").OnClientEvent:Connect(transMove)
print("received")
That would definitely help to start out, lmao. I receive the error:
13:18:50.012 - Players.stalecars.PlayerGui.ScreenGui.Client :144: attempt to index a nil value
13:18:50.014 - Stack Begin
13:18:50.014 - Script 'Players.stalecars.PlayerGui.ScreenGui.Client ', Line 144 - function transMove
13:18:50.015 - Stack End
local function transMove(player)
print("received")
local playerGui = player.PlayerGui -- Line 144
local transition = playerGui:FindFirstChild("TransitionFrame")
local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
local maxTrans = {
Transparency = 0,
BackgroundColor3 = Color3.new(1,1,1)
}
local tween = Client.tweenService:Create(transition,info,maxTrans)
tween:Play()
tween.Completed:Wait()
transStart(playerGui)
end
I’m very sure that the localplayer passed on during the remoteevent shouldn’t be nil even though it is printed as nil
It is nil, the first argument in a remoteEvent:FireClient is the receiving player, not the argument that is passed to the function.
Though you could fix this by adding localplr as the second argument as well as the first, I would rather index the player through the client using game:GetService("Players").LocalPlayer
Example:
local LocalPlayer = game:GetService("Players").LocalPlayer
local function transMove()
local playerGui = LocalPlayer.PlayerGui
-- The rest.
end
local function transMove(plr)
print(Client.localPlayer)
print("received")
local playerGui = Client.localPlayer.PlayerGui
local transition = playerGui.ScreenGui:FindFirstChild("TransitionFrame")
local info = TweenInfo.new(2, Enum.EasingStyle.Quint,Enum.EasingDirection.In)
local maxTrans = {
Transparency = 0,
BackgroundColor3 = Color3.new(1,1,1)
}
local tween = Client.tweenService:Create(transition,info,maxTrans)
playerGui.ScreenGui.TransitionFrame.Visible = true
tween:Play()
tween.Completed:Wait()
transStart(playerGui.ScreenGui)
end
Nothing is happening however, event is fired but the gui does not become visible or anything.