Need to locate event!

hello guys i am currently making mobile buttons for my swordfighting game but, i can’t locate the event inside the tool of the player character…
the gui is located in the “PlayerGui

i have tried locating it with this script before but it didnt work…
the event is located in the tool when the tool is held

local plr = game.Players.LocalPlayer
local char = plr.Character
local remoteEvent = char.FindFirstChild("Lightsaber")["Enable/Disable"].EnableSaber -- doesnt locate the event in the players tool
function onclick()
remoteEvent:FireServer()
	script.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.WhenEnabled.Visible = true
	script.Parent.Ignite:Play()
end

script.Parent.MouseButton1Click:connect(onclick)

i need help on this!

2 Likes

It’s because you’re trying to find the lightsaber before it’s even in the players hand, you should check every time the player pulls the lightsaber out

2 Likes

try this

local tool = --put the tool here
tool.Equipped:Connect(function()
local plr = game.Players.LocalPlayer
local char = plr.Character
local remoteEvent = char.FindFirstChild("Lightsaber")["Enable/Disable"].EnableSaber -- doesnt locate the event in the players tool
function onclick()
	script.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.WhenEnabled.Visible = true
	script.Parent.Ignite:Play()
end

script.Parent.MouseButton1Click:connect(onclick)
end)
2 Likes

now how would i go ahead and do this?

1 Like

First of all, are you doing this in a serverscript or local script?

2 Likes

local bc i want it to play on the client and replicate it on the server with the remoteEvent:FireServer()
wich i need to locate but i cant locate it sadly :confused:

1 Like

btw the gui only goes to the playergui when the tool is eqquiped so i got that covered

1 Like

I recommended learning the basic understanding of scripting before dealing with stuff like this but anyways try this:

did some edits

2 Likes

this sadly doesnt work and yes i do know how to script only i need to locate 1 event in a tool from the playergui not “StarterGui” and the gui is only in the playergui when a mobile player is holding the tool

1 Like

Wait… the event is inside the PlayerGui or the character?

2 Likes

its located in the tool wich is in the character when the plr holds the tool

1 Like

I made some edits again. try this:

local tool = script.Parent
tool.Equipped:Connect(function()
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local remoteEvent = tool:FindFirstChild("Enable/Disable").EnableSaber
function onclick()
    remoteEvent:FireServer()
	script.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.WhenEnabled.Visible = true
	script.Parent.Ignite:Play()
end

script.Parent.MouseButton1Click:connect(onclick)
2 Likes

I just figured out something. The previous guy who originally made this script made an error

2 Likes

so could you also show explorer and path of the gui and where it goes when it is duplicated.

2 Likes

ofc thanks for helping me but this isnt what i mean XD

local tool = script.Parent

isnt where the tool is located and i need to locate it

1 Like

ama try doing it via ReplicatedStorage and see what kind off effect it gives

1 Like

The local script isn’t in the tool?

2 Likes

no its in the gui button… 30 letters

1 Like

Ahhhhhh. That’s the issue.

A script cannot be used as a tool unless it is the child of a tool.

2 Likes

this might make evrybody enable their lightsaber so i dont know ab this (BUT ATLEAST i got something to work)

robloxapp-20230329-1606191.wmv (1.1 MB)

2 Likes