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

why won t this script work on roblox player?

Asked by
Benqazx 108
8 years ago
script.Parent.MouseButton1Click:connect(function()
-- Inside Server Script
local event = Instance.new("RemoteEvent") -- creates the event object
event.Parent = game.Workspace -- puts the event into the Workspace
event.Name = "MyServerEvent" -- giving a name to the event so we can fire it specifically elsewhere
event.OnServerEvent:connect(function() -- define the function that will be called when the event is fired
    local player = script.Parent.Parent.Parent.Parent
    local char = player.Character
    local human = char:FindFirstChild("Humanoid")
    local model = script.Parent.Parent.Model.Value
    local car = script.Parent.Parent.Car.Value
    if human:FindFirstChild(model)~= nil then
        print("Model Found!")
        if human:FindFirstChild(model):FindFirstChild(car) ~= nil then
            print("Car Found!")
            local body = human:FindFirstChild(model):FindFirstChild(car):GetChildren()
            for i,v in pairs (body) do
                if v.Name == "Seat" then
                    v.Disabled = true
                    script.Parent.Parent.Open.Visible = true
                    script.Parent.Visible = false
                end
            end
        end
    end
end)
    game.Workspace.MyServerEvent:FireServer()
end)

this script works on studio but not on the roblox player. the error below pops up. why? please help 23:29:39.113 - OnServerEvent can only be used on the server 23:29:39.114 - Script 'Players.Player2.PlayerGui.VehicleGui.Lock.LocalScript', Line 6 23:29:39.114 - Stack End

2 answers

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

Lines 1-6 should be in a server script, not local.

The source explains this.

Ad
Log in to vote
1
Answered by 8 years ago

You can't handle the server side part of a RemoteEvent; you have to place to OnServerEvent Code in a Server Script.

Answer this question