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

Why the RemoteEvent is only woking in-Studio but not in-Game?

Asked by 5 years ago

i made 2 scripts connected to each other using RemoteEvent to give player a uniform if he answer with "Yes" (Dialog)

But.. its only working if i tested in-studio, and its not working in-game.

the First located in the NPC

local debounce = true
local UniEvent = game.ReplicatedStorage:WaitForChild("UniformGiveEvent")

script.Parent.DialogChoiceSelected:connect(function(player, choice)
    if choice == script.Parent.Yes then
        if debounce then
            debounce = false
            UniEvent:FireServer()
        end
    end
end)

and the Second located in the ServerScriptService

local Event = Instance.new("RemoteEvent")
Event.Parent = game.ReplicatedStorage
Event.Name = "UniformGiveEvent"
local Shirt = "rbxassetid://000000000" -- Random code
local Pants = "rbxassetid://000000000" -- Random code

function GiveUni(plr)
    local character = plr.Character
    local shirt = character.Shirt
    local pants = character.Pants
    shirt.ShirtTemplate = Shirt
    pants.PantsTemplate = Pants
end

Event.OnServerEvent:Connect(GiveUni)

Please Help Me!

0
were there any errors in game on the devloper tab? TheOwlFromSaturn 26 — 5y
0
Why don't you just make the event yourself instead of having the script do it? Also are your scripts local or server? DominousSyndicate 41 — 5y
0
I love using a Wok to cook with. unmiss 337 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

It "works" in studio because you used Play Solo mode. Play Solo is the server and client combined, they are one. There is no separation between the two, so this is why local scripts may have access to things they shouldn't have access to, such as the ServerStorage service. Use local servers to test scripts instead.

Anyway, since DialogChoiceSelected is server-sided, you don't need any RemoteEvents. The uniform giving script can also error if a player doesn't have a shirt or pants.

local Shirt = "rbxassetid://000000000" -- Random code
local Pants = "rbxassetid://000000000" -- Random code
local debounce = true

local function GiveUni(plr, choice)
    if choice == script.Parent.Yes then
        if debounce then
            debounce = false 
            local character = plr.Character
            local shirt = character:FindFirstChild("Shirt") or Instance.new("Shirt")
            local pants = character:FindFirstChild("Pants") or Instance.new("Pants")
            shirt.ShirtTemplate = Shirt
            pants.PantsTemplate = Pants
            shirt.Parent = character
            pants.Parent = character
        end
    end
end

script.Parent.DialogChoiceSelected:Connect(GiveUni)
0
nope :( its not working tho SherifG4mer 0 — 5y
0
now its not even working in-studio :I SherifG4mer 0 — 5y
Ad

Answer this question