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

Needing help with remote events?

Asked by
Smoho 2
6 years ago

I am having an issue with a character menu I have created: In single-player, the game seems perfectly normal. All of the buttons work, you can select a character, the animations play and all that. Yet, in a multiplayer environment, once someone has selected a character to become, they may have this experience, yet everyone else sees them as a non-moving avatar, and not the character.

I believe the error may be that the transformation appears to the client -as it is on a LocalScript, within a GUI-, and that it may require the assistance of a remote event in order to appear to everybody else. However, I am unfamiliar with Remote Events, and have unsteadily pieced together this modification of my prior scripting.

--Local Script
local button = script.Parent
local player = button.Parent.Parent.Parent.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("MorphEventBLT")

button.MouseButton1Down:Connect(function()
    Event:FireServer()
end)
--Script
local morph = game.ReplicatedStorage.Beanlet
local player = button.Parent.Parent.Parent.Parent.Parent

local ReplicatedStorage = game.GetService("ReplicatedStorage")
local Event = Instance.new("RemoteEvent", ReplicatedStorage)
Event.Name = "MorphEventBLT"

local function onEventFired()
    local pos = player.Character.HumanoidRootPart.CFrame
    local oldhuman = player.Character
    player.Character = morph:Clone()
    oldhuman:Destroy()
    player.Character.Parent = workspace
    player.Character.HumanoidRootPart.CFrame = pos
end

Event.OnServerEvent:Connect(onEventFired)

The first immediate issue is that the script does not create a remote event, despite it supposedly doing it in some of the first lines of code. The Studio has Accurate Play Solo enabled, and does not generate any errors within the Output, other than the Local Script stating that MorphEventBLT has an infinite yield. Should I add the remote event manually? I had tried earlier, and it did not work in a multiplayer environment.

2 answers

Log in to vote
0
Answered by 6 years ago
--Script
local morph = game.ReplicatedStorage.Beanlet
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = Instance.new("RemoteEvent", ReplicatedStorage)
Event.Name = "MorphEventBLT"

local function onEventFired(player)
    local pos = player.Character.HumanoidRootPart.CFrame
    local oldhuman = player.Character
    player.Character = morph:Clone()
    oldhuman:Destroy()
    player.Character.Parent = workspace
    player.Character.HumanoidRootPart.CFrame = pos
end

Event.OnServerEvent:Connect(onEventFired)
0
I tried that solution, and it let me morph into the character, yet the character still does not appear to other players? Smoho 2 — 6y
Ad
Log in to vote
0
Answered by
Smoho 2
6 years ago

Update, not an answer: I've been messing with it a bit more, and now I have the events premade, and what seems to still be the problem is that the local script will work, but the script won't. I found out scripts don't exactly work in GUIs, so I've moved it to ServerScriptService, and it still doesn't work. It doesn't seem to give any type of errors, either. I don't understand what I'm doing incorrectly?

--Script
local morph = game.ReplicatedStorage.Beanlet
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = Instance.new("RemoteEvent", ReplicatedStorage)
Event.Name = "MorphEventBLT"

local function onEventFired(player)
    print("Hired!")
    local pos = player.Character.HumanoidRootPart.CFrame
    local oldhuman = player.Character
    player.Character = morph:Clone()
    oldhuman:Destroy()
    player.Character.Parent = workspace
    player.Character.HumanoidRootPart.CFrame = pos
end

Event.OnServerEvent:Connect(onEventFired)
--Local Script
local button = script.Parent
local morph = game.ReplicatedStorage.DarkStarCore
local player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("MorphEventBLT")

button.MouseButton1Click:Connect(function()
    Event:FireServer(player)
    print("Fired!")
end)


0
Ignore the change in characters, please! Smoho 2 — 6y

Answer this question