Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I don't know how to convert my script to LocalScript correctly without breaking it?

Asked by 6 years ago

I've tried every tutorial I've found on every possible platform, but to no avail. Can anyone show me the proper way to convert this to a working LocalScript without it breaking? The script is completely functional on Studio but not the game itself.

repeat wait() until game.Players.LocalPlayer.Character
wait(1)
game:GetService("Players")
local player = game.Players.LocalPlayer
local egghunt = player.Character.Humanoid
print("Cash")

function onPlayerEntered(newPlayer)
    wait(.25)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local stats2 = Instance.new("IntValue")
    stats2.Name = "Cash"

    local cash = Instance.new("IntValue")

    cash.Name = "Cash"
    cash.Value = 0

    cash.Parent = stats
    stats2.Parent = newPlayer   
    stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)






----------------------------------------------------------------
ZombieWaveTime = math.random (60) --put how long in seconds wave
InbetweenZombieWaveTime = 10 -- inbetween zombie wave
MessageShowTime = 5 --  announcement messages 
while true do
local msg = Instance.new("Message")--Copy from here
msg.Parent  = game.Workspace
msg.Text = ("Let's wait 15 seconds for other people to join.")
wait(5)
msg:remove()
wait(5)
local msg = Instance.new("Message")
msg.Parent  = game.Workspace
msg.Text = ("The game will begin in 1 minute.")
wait(5)
msg:remove()
wait(5)
local msg = Instance.new("Message")
msg.Parent  = game.Workspace
msg.Text = ("The game will begin in 30 seconds!")
wait(5)
msg:remove()
wait(5)
local msg = Instance.new("Message")
msg.Parent  = game.Workspace
msg.Text = ("The game begins in 5...")
wait(1)
msg.Text = ("The game begins in 4...")
wait(1)
msg.Text = ("The game begins in 3...")
wait(1)
msg.Text = ("The game begins in 2...")
wait(1)
msg.Text = ("The game begins in 1...")
wait(1)
msg:remove()
wait(1/30)--

target = CFrame.new(0, 50, 0) 
for i, player in ipairs(game.Players:GetChildren()) do
    player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
    --offset of 5
end
wait(1)


local PlayersDied = 0

egghunt.Died:connect(function ()
    PlayersDied = PlayersDied + 1
    if PlayersDied >= game.Players.NumPlayers then -- if someone left
    local msg = Instance.new("Message")
    msg.Parent = game.Workspace
    msg.Text = ("The game is over!")
    wait(5)
    msg:remove()
    script.Disabled = true








        PlayersDied = 0 --Reset the dead count
    end
end)
local msg = Instance.new("Message")--Copy from here
msg.Parent  = game.Workspace
msg.Text = ("Wave 1")--  
wait(5)-- 
msg:remove()
game.Lighting.Wave1:clone().Parent = game.Workspace
game.Workspace.Wave1:MakeJoints()
wait(ZombieWaveTime)
game.Workspace.Wave1:remove()
wait(InbetweenZombieWaveTime)
----------------------------------
local msg = Instance.new("Message")
msg.Parent  = game.Workspace
msg.Text = ("Wave 2")
wait(5)
msg:remove()
game.Lighting.Wave2:clone().Parent = game.Workspace
game.Workspace.Wave2:MakeJoints()
wait(ZombieWaveTime)
game.Workspace.Wave2:remove()
wait(InbetweenZombieWaveTime)
----------------------------------
end

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

To get a player's character client-side, this is better:

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

RBXScriptSignal:Wait() will return the arguments fired to the event, so that's why that code works.

Instance:remove() is deprecated, use Instance:Destroy() instead. Also, Instnace:Clone()

You shouldn't use game.Lighting to store things anymore. Instead, prefer game.ServerStorage for anything that doesn't need to be replicated to the client at all times, and game.ReplicatedStorage for stuff that does.

Prefer RBXScriptSignal:Connect() with a capital C, as the lowercase version is deprecated.

In addition, Message objects are also deprecated. Perhaps consider using a GUI.

Stuff like handling when players join and the main game loop should be done server-side, not client-side. Client-side code will run on every client, while you want this stuff to happen just once.

Please indent your code, with one indent per level of scope.

I'd use Character:WaitForChild("Humanoid") as there is no guarantee of character children being accessible when Player.CharacterAdded fires as far as I'm aware.

In Studio's Play Solo testing, there is no separation of client and server. If you need that, try the Test Server option.

0
So would separating the scripts be the best way to go with this? And if so, what parts would I separate? CyborgCaesar 9 — 6y
Ad

Answer this question