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

ServerScriptService is not a valid member of DataModel?

Asked by 7 years ago

The script works flawlessly with no errors in studio, but when i play in game, i get the error ServerScriptService is not a valid member of DataModel on line 11. Anyone know why?

Local Script

--Libraries
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera
local rs = game:GetService('RunService').RenderStepped
local uis = game:GetService('UserInputService')

--Fundmental Modules
local gs = require(game.ReplicatedStorage.Modules.Fundementals.GameSettings)
local eai = require(game.ServerScriptService:WaitForChild("Modules").Classes.Enemy.EmemyAi)

--Events
local events = game.ReplicatedStorage.Events
local signal = events:WaitForChild("Signal")

--Variables
local ct = 4

--Main
signal.OnClientEvent:connect(function(ver,p1,p2,p3)
    local bdfl = {
        SetupTurret = function()
            local clp = true
            local lastrot = {
                x=0,
                y=0,
                z=0,
            }
            --Cloning
            local t = game.ReplicatedStorage.Assets.Turrets.RTurret:Clone()
            t.Parent = cam

            --Input
            uis.InputBegan:connect(function(io,gpe)
                if io.KeyCode == Enum.KeyCode.R and clp == true then
                    if t:isA('Model') then
                        if t.PrimaryPart ~= nil then
                            t:SetPrimaryPartCFrame(t:GetPrimaryPartCFrame()*CFrame.Angles(0,math.rad(5),0))
                            lastrot.y = t.PrimaryPart.Rotation.Y
                        else
                            warn("Set Primary Part to base...")
                        end
                    elseif t:isA('BasePart') then
                    t.CFrame = t.CFrame*CFrame.Angles(0,math.rad(5),0)
                    lastrot.y = t.Rotation.Y
                    end
                end
            end)

            local function castRay(o,o2)
                local mag = (o.PrimaryPart.Position-o2.Position).magnitude
                local beam = Instance.new('Part')
                beam.BrickColor = BrickColor.new('Really Red')
                beam.Material = 'Neon'
                beam.Transparency = 0
                beam.Anchored = true
                beam.CanCollide = true
                beam.Size=Vector3.new(0.3,0.3,mag)
                beam.CFrame=CFrame.new(o.PrimaryPart.Position,o2.Position)*CFrame.new(0,0,-mag/2)
                beam.Parent = cam
                game:GetService("Debris"):AddItem(beam,4)
            end

            local function trackEnemies(o)
                local cooldown = 0
                local closestpart
                spawn(function()
                    while wait() do
                        wait(cooldown)
                        if #gs.CurrentCourse.Enemies:GetChildren()~= 0 then
                            cooldown = 0
                            for n,e in pairs(gs.CurrentCourse.Enemies:GetChildren()) do
                                if e ~= nil then
                                    local mag = (o.PrimaryPart.Position-e.Position).magnitude
                                    if mag <= 4.5 then
                                        closestpart = e
                                    end
                                end
                            end
                                if closestpart then
                                    castRay(o, closestpart)
                                    signal:FireServer('Backdoor','DestroyEnemy',closestpart)
                                    closestpart = nil
                                    cooldown = ct
                                end
                            end
                        end
                    end)
                end         

            mouse.Button1Down:connect(function()
                clp = false
                trackEnemies(t)
            end)

            mouse.TargetFilter = t

            rs:connect(function()
                if clp == true then
                        if mouse.Target ~= nil then
                            if mouse.Target.Parent.Parent == gs.CurrentCourse then
                            signal:FireServer('Backdoor','UpdateTurretPosition',t,
                            CFrame.new(mouse.Target.Position.X,((t.PrimaryPart.Size.Y/2)+mouse.Target.Position.Y)+0.5,mouse.Target.Position.Z)*CFrame.Angles(0,lastrot.y,0))
                        end
                    end
                end
            end)
        end
    }
    if ver == 'Backdoor' then
        bdfl[p1](p2,p3)
    elseif ver == 'Frontdoor' then
        signal:FireServer('Backdoor',p1,p2,p3)
    end
end)

1 answer

Log in to vote
2
Answered by
Decemus 141
7 years ago

Use game:GetService('ServerScriptService') instead. Sometimes it may not load it right away, so just do that to get it.

Ad

Answer this question