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

RemoteEvent Script. Works in studio, but not in actual server?

Asked by 8 years ago

Well, Basically I tried to follow the "RemoteFunction and RemoteEvent Tutorial" Roblox offered. And I ended up with this script in 'ServerScriptService' with another script in that script. I'm not 100% sure about how Server and Local Scripts go in this process. But I got it to work in studio. May I also mention, I have Filtering Enabled Turned ON.

Here is the Server Script [According to What I thought]:

wait(5)
local event = Instance.new("RemoteEvent") 
event.Parent = game.Workspace 
event.Name = "LeftDoorEvent"

event.OnServerEvent:connect(function()
    local Door = game.Workspace.LeftDoor1
    local main = Door:GetPrimaryPartCFrame()
    local part = Door.PrimaryPart
    local clic = Door.ClickDetector
    local sound = Door.Sound 
    if Door.Open.Value == 1 then 
        sound:Play()
        local fix = Door.Main.CFrame 
    for i = 0,1.5,0.1 do
        wait(0.05)
        Door:SetPrimaryPartCFrame(Door.Main.CFrame*CFrame.fromEulerAnglesXYZ(0,-0.1,0)*CFrame.new(0.01,0,-0.25))
        Door.Open.Value = 0
        clic.MaxActivationDistance = 0
    end
        Door:SetPrimaryPartCFrame(fix*CFrame.fromEulerAnglesXYZ(0,-math.pi/2,0)*CFrame.new(-2.5,0,-2.5))
        wait(0.25)
        clic.MaxActivationDistance = 15
    elseif Door.Open.Value == 0 then
        sound:Play()
        local fix = Door.Main.CFrame 
    for i = 0,1.5,0.1 do
        wait(0.05)
        Door:SetPrimaryPartCFrame(Door.Main.CFrame*CFrame.fromEulerAnglesXYZ(0,0.1,0)*CFrame.new(-0.01,0,0.25))
        clic.MaxActivationDistance = 0
    end
        Door:SetPrimaryPartCFrame(fix*CFrame.fromEulerAnglesXYZ(0,math.pi/2,0)*CFrame.new(-2.5,0,2.5))
        wait(0.25)
        clic.MaxActivationDistance = 15
        Door.Open.Value = 1
    end 
end)

The Script above activates once the door is clicked from a ServerEvent

This next script is what Roblox called "The Local Script"

wait(5)
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = game.Workspace.LeftDoor1
clickDetector.MouseClick:connect(function(hit)
    game.Workspace.LeftDoorEvent:FireServer()
end)

The above script is suppose to fire the server thing and cause the door to move. Which activates the server script. This script is a Child of the ServerScript.

I do not understand the problem. Maybe I formatted something wrong, or the scripts are the wrong type, or in the wrong location?

ServerScript:IsA - regular Script just in ServerScriptService LocalScript:IsA - regular Script and its parent is the ServerScript.

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

Your problem is that the 'local script' has to be an actual LocalScript!

Additionally, LocalScripts won't run except in:

  • The Workspace as a descendant of the LocalPlayer's Character Model.
  • The LocalPlayer's PlayerGui.
  • The LocalPlayer's Backpack.
  • The LocalPlayer's PlayerScripts.
  • ReplicatedFirst

The middle three have associated 'Starter' containers as well: StarterGui, StarterPack, and StarterPlayerScripts (although this one is a descendant of the Players Service.)

Putting the LocalScript directly in one of these containers will work for you.

0
okay ill try it out thanks! CarterTheHippo 120 — 8y
0
This again, only worked in studio. I'm so confused! CarterTheHippo 120 — 8y
Ad

Answer this question