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

How do I pass object values in remove events? (If possible) [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I have the following script in a players "Events" that play localy depending on the players actions:

script:WaitForChild("Hide_Under_Bed").OnClientEvent:connect(function(BedObject)
    if BedObject then
    print(BedObject.Focus.Position) --Print an object's position in that model.
    else
        print("Y you do dis")
end 
end)

And also this script in the object:

script.Parent.MouseClick:connect(function(player)
    repeat wait() until player.Character
    player.Character:WaitForChild("Events"):WaitForChild("Main"):WaitForChild("Hide_Under_Bed"):FireClient(script.Parent.Parent)
end)

Here I want to pass the object value to the player's event as a parametrer so I don't have to write "game.Workspace...". I would do it, but I have multiple of these with the same name so roblox would not know which one is the correct one.

I don't know if that even is possible or not. If it is it would be nice to give me some guidance here on how to pass it correctly without getting the "attempting to index.." error, if not any idea on how to get the object I want with the same name as many others.

If confused let's say I have 10 Models called "Table" in workspace. But I want to get a ESPECIFIC table from those 10 without calling it's name because roblox would not know which one it is. That's basically it

0
no1 knows for real dareveloper 9 — 6y
0
Is this a troll account? It better be wilsonsilva007 373 — 6y
0
my account is: nextgenplatform, please help me on my post because i got some scripting problems too dareveloper 9 — 6y
0
make variables like.. local Events = player.Charcater:WaitForChild('Events') awesomeipod 607 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

You forgot to add something in your second script. :FireClient() has a first argument that requires the player to know which player it will fire to.

Line 3 should be something like this :

player.Character:WaitForChild("Events"):WaitForChild("Main"):WaitForChild("Hide_Under_Bed"):FireClient(player, script.Parent.Parent)

You'll notice at the end of the line, I added the parameter "player" from the function. This will fire the remote event specifically to the "player" and it should send whatever "script.Parent.Parent" is.

Hoped this helped!

0
I work with remote functions,events and etc for months and I can't belive how stupid I can be sometimes.. Thank you so much! wilsonsilva007 373 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
--server script

local Parent = script.Parent.Parent

script.Parent.MouseClick:connect(function(player)
-- // variables
local Events = player.Character:WaitForChild('Events')
local Main = Events:WaitForChild('Main')
local HideEvent = Main:WaitForChild('Hide_Under_Bed')

-- // fire event
repeat wait() until player.Character
HideEvent:FireClient(Parent)
end)

0
Workspace.wilsonsilva007.Events.Main:394: attempt to index local 'BedObject' (a nil value) wilsonsilva007 373 — 6y

Answer this question