Script works fine in studio but gives error in game

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:Connect(function()
ReplicatedStorage:FindFirstChild("EquipSword"):FireServer(script.Parent.Name)--line5
end)

Script is in a Gui in a local script

1 Like

Is your script a local script or regular script?

I have a similar script that i used to fire a remote event

local RemoteEvent = game.ReplicatedStorage:WaitForChild("SyrupEvent")
local prox = script.Parent

prox.Triggered:Connect(function(player)
	RemoteEvent:FireClient(player)
end)

this is a regular script, and it was used for a ProximityPrompt so i placed it right under, i see you are trying to make it work with im guessing a gui button right?

1 Like

It all worked fine until i changed the script in the server script that receives the data from the event

1 Like
  1. Verify if “EquipSword” exists
  2. define the Event at start of the script using :WaitForChild() instead of :FindFirstChild()

ReplicatedStorage:FindFirstChild(“EquipSword”):FireServer(tostring(script.Parent.Name))
fixed it

and your code will look like this

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("EquipSword")

script.Parent.MouseButton1Click:Connect(function()
   Event:FireServer(script.Parent.Name)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.