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

My RemoteEvent won't fire, what is the problem?

Asked by 9 years ago

Hi there! I am making a pretty simple script, where when a player touches a part, it is put on their back and it fires a message telling a localscript that the part is "picked up." However, it doesn't seem like the two scripts recieves, or even sends any information. I don't know if this has something to do with it being a part that is in workspace or not. Anyway, here are my two scripts:

****ServerScript

local bag = script.Parent

local moneyinbag = bag.Money.Value

local event = bag:FindFirstChild("RemoteEvent")

local eventfired = false

bag.Touched:connect(function(hit)

    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local torso = hit.Parent:FindFirstChild("Torso")

    if humanoid and torso then
        local bagweld = Instance.new("Weld")
        player = hit.Parent

        if player then
            event:FireClient(player, "PickUp", hit)
            print("pickedup") -- this is printed after the part is touched

            bagweld.Name = "BagWeld"

            print(hit.Parent) -- shows my player

            bagweld.Parent = hit.Parent.Torso
            bagweld.Part0 = torso
            bagweld.Part1 = bag
            bagweld.C1 = CFrame.new(0, 0, -1)
        end
    end
end)

event.OnServerEvent:connect(function( ... )
    local tuple = { ... }
    if tuple[1] == "Throw" then
        print("works") -- this is not printed
        local bagweld = player.Torso:WaitForChild("BagWeld")
        if bagweld then
            bagweld.C1 = CFrame.new(0, 0, 1)
            bagweld:Destroy()
        end
        local force = Instance.new("BodyForce")
        force.force = Vector3.new(0, 100, 0)
        force.Parent = bag
    end
end)

****Local Script

--Scripted by SonioSony

local bag = script.Parent

local moneyinbag = bag.Money.Value

local event = bag:FindFirstChild("RemoteEvent")
local pickedup = false

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local bagscreen = game.StarterGui:WaitForChild("BagScreen")

event.OnClientEvent:connect(function( ... )
    local tuple = { ... }
    if tuple[1] == "PickUp" then
        pickedup = true
        if bagscreen then
            bagscreen.TextBox.Visible = true
        end
        player = tuple[2].Parent
        mouse = player:GetMouse()
    end
end)

mouse.Button1Down:connect(function()
    print("yes") -- to check if anything happens, didn't work
end)

mouse.KeyDown:connect(function(key)
    if key "g" and pickedup then
        event.FireServer("Throw")
        local bagweld = player.Torso:WaitForChild("BagWeld")
        if bagweld then
            bagweld:Destroy()
        end
        local force = Instance.new("BodyForce")
        force.force = Vector3.new(0, 100, 0)
        force.Parent = bag
    end
end)

I am pretty new to scripting, so I am greatful for help!

0
You have a syntax error in your script, `if key "g"`, which is why nothing is working. Turn it to `if key == "g"`. Diitto 230 — 9y

Answer this question