-- ServerScript Inside a Textlabel
local timer = script.Parent
local rs = game:GetService("RunService")
local reps = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").PlayerAdded
local currentwalkspeed = 12
local maxtimer = 30
local function deleteLoadingGame ()
reps.WalkSpeed:FireClient(player, currentwalkspeed) -- player parameters issue
task.wait()
timer.Parent.Parent:Destroy()
end
timer.Text = maxtimer
repeat wait(1) timer.Text -= 1 until timer.Text == "-1"
timer.Text = ""
task.delay(5,deleteLoadingGame)
-- LocalScript inside StarterCharacterScript
local reps = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
reps.WalkSpeed.OnClientEvent:Connect(function (player, walkspeed)
plr.Character.Humanoid.WalkSpeed = walkspeed
end)
The error like : “unable to cast value to object” and PlayerAdded didn’t run the code.
I’ve tried many solution and still didn’t work like game.Players.PlayerAdded or game.Players:GetPlayers(). So is there a way to get a specific player on the serverscript?
You want to run the deleteLoadingGame whenever a player joins. And the way you do it is by connecting it to the playerAddedd event instead of what you did.
-- ServerScript Inside a TextLabel
local timer = script.Parent
local reps = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local currentwalkspeed = 12
local maxtimer = 30
local function deleteLoadingGame(player)
reps.WalkSpeed:FireClient(player, currentwalkspeed)
wait()
timer.Parent.Parent:Destroy()
end
timer.Text = maxtimer
repeat
wait(1)
timer.Text = timer.Text - 1
until timer.Text == "0"
timer.Text = ""
-- you can just do Players.PlayerAdded:Connect(deleteLoadingGame) too
Players.PlayerAdded:Connect(function(player)
-- we call the function on that player that joined
deleteLoadingGame(player)
end)