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

Help with remote event?

Asked by
Roytt 64
8 years ago

I have this inside a localscript in startergui


local p = game.Players.LocalPlayer local m = p:GetMouse() local s = game.Workspace:WaitForChild("select") for _, v in pairs(s:GetChildren()) do m.Move:connect(function(gui) if m.Target == v and p:DistanceFromCharacter(v.Position)< 50 then v.BillboardGui.Enabled = true m.Button1Down:connect(function(a) game.Workspace.Mouse:FireServer() end) else v.BillboardGui.Enabled = false end end) end

and this inside a serverside script for the remote event

local event = Instance.new("RemoteEvent") -- creates the event object
event.Parent = game.Workspace -- puts the event into the Workspace
event.Name = "Mouse" -- giving a name to the event so we can fire it specifically elsewhere
event.OnServerEvent:connect(function(player, part) -- define the function that will be called when the event is fired
        print(part.Name)
end)

How can I make it so it prints the name of the part located inside the "select" model which was clicked by the player?

1 answer

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

When you do the FireServer(), you need to pass in the actual part touched. In this case, v.

There's also another major issue with your client-side code; by connecting the events inside of loops, you are creating an excessive number of event connections.

Additionally, the Button1Down event gets connected regardless of if they just clicked or not, so an excessive amount of fireserver calls will be made, regardless of if the user was clicking on a specific part or not, or none will be created at all.

Either way, bad design.

local p = game.Players.LocalPlayer
local m = p:GetMouse()
local s = game.Workspace:WaitForChild("select")

m.Button1Down:connect(function()
    if m.Target.Parent == s and p:DistanceFromCharacter(m.Target.Position) < 50 then
        game.Workspace.Mouse:FireServer(m.Target)
    end
end)

m.Move:connect(function()
    for _, v in pairs(s:GetChildren()) do
        if v ~= m.Target then
            v.BillboardGui.Enabled = false
        else
            v.BillboardGui.Enabled = true
        end
    end
end)

0
What can I do to fix the design problems you listed? Roytt 64 — 8y
0
it also seems that my script had a line missing, how can I include it inside the script? (line 08) Roytt 64 — 8y
0
Ah, I thought I was missing somthing. My code fixed the majority of the issues, but it'll take another segment to activate the billboard again. adark 5487 — 8y
Ad

Answer this question