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

Why does the ServerScriptService remove all its children when I test the game?

Asked by 4 years ago
Edited 4 years ago

The ServerScriptService seems to remove the items inside it when I test a fireball script in Studio.

Heres the code:

--StarterPlayerScripts



local UIS = game:GetService("UserInputService") local mouse = game.Players.LocalPlayer:GetMouse() local debounce = false UIS.InputBegan:Connect(function(key, processed) print("inputted") if processed or debounce then return end if key.KeyCode == Enum.KeyCode.Q then debounce = true print("q pressed") game:GetService("ServerScriptService").FireballScript.RemoteEvent:FireServer(mouse.Hit.Position) end wait(1) debounce = false end)

--ServerScriptService (inside is a RemoteEvent called RemoteEvent)

script.RemoteEvent.OnServerEvent:Connect(function(Player, Mouse)

    print("remote event fired")
    local Fireball = game:GetService("ServerStorage").Fireball:Clone()
    local Explosion = game:GetService("ServerStorage").Explosion:Clone()
    local Character = Player.Character


    Fireball.Position = Character.HumanoidRootPart.Position
    Fireball.Parent = workspace
    local velocity = Instance.new("BodyVelocity", Fireball)
    velocity.Velocity = CFrame.new(Fireball.Position, Mouse).LookVector * 100


    Fireball.Touched:Connect(function(Touched)
        if Touched:IsDescendantOf(Character) then return end

        Explosion.Position = Fireball.Position
        Fireball:Destroy()
        Explosion.Parent = workspace

        if Touched.Parent:FindFirstChild("Humanoid") then
            Touched.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
        end

        wait(2)
        for i = 1, 300 do
            Explosion.Fire.Size = Explosion.Fire.Size - 0.08
            Explosion.Fire.Heat = Explosion.Fire.Heat - 0.03
            wait()
        end
        Explosion:Destroy()
    end)
end)

2 answers

Log in to vote
0
Answered by 4 years ago

NVM Problem solved. I tried putting the Server-sided Script in the Workspace. It works now.

0
it dosent achually remove the contents inside SSS. It only appears that way because when you are testing you are in client mode. Change it to server mode and you will see the context. It is SERVER script service, which is a directory which stores scripts on the server. This is why you cannot see it when testing, only if you change the mode to the server. RBLXNogin 187 — 4y
0
glad you found your solution royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by
RBLXNogin 187
4 years ago

It dosen't achually remove the contents inside ServerScriptService. It only appears that way because when you are testing you are in client mode. Change it to server mode and you will see the context. It is SERVER script service, which is a directory which stores scripts on the server. This is why you cannot see it when testing, only if you change the mode to the server.

As I have said on several other questions, Scripts runs "server sided" (which basically means on the roblox server), which allows scripts to be ran for all players. Local scripts run "on your computer/ for the current player". This uses Client-Sided events and properties such as getting the player with game.Players.LocalPlayer or getting the camera/mouse.

Here is a quotation from ScriptingHelpers user: Destrings, which explains this concept clearly:

ROBLOX makes a distinction between code run on the clients and code run on the server, calling the Local Scripts and Scripts respectively. As this code is run on the client it has access to client only entities, like the camera, but does not have access to server only entities: Remember both the client and server maintain their state independently: the client updates said state when the server request it to and vice-versa (if the server trust the client).

That being said, remember that inorder to see what the server is handling you can switch to "Server" mode when testing. The default mode when testing is client, which is why you are unable to see your objects in ServerScriptService when you click play

Answer this question