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

Tool works in Studio but not on Server. RemoteEvent is not a valid member of tool? Help?

Asked by 6 years ago

I have multiple tools that work in Studio but not on a server. The example I will use is the magic wand used as an example in the tools section of Roblox wiki, because one would think that the example tool would work. I get the error that RemoteEvent is not a valid member of tool (when testing on server, otherwise, no error). Like I said, works great in studio and not at all on a server. Thanks.

my tool is laid out: BlockTool Script LocalScript RemoteEvent Handle

-- Local Script local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local clickEvent = tool.RemoteEvent

local function onActivate() local clickLocation = mouse.Hit clickEvent:FireServer(clickLocation) end

tool.Activated:connect(onActivate)

-- Server Script local tool = script.Parent local clickEvent = tool.RemoteEvent local clickEventConnection

local function createPart(location) local part = Instance.new('Part') part.CFrame = location part.Parent = workspace end

local function onClick(player, clickLocation) createPart(clickLocation) end

local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end

local function onUnequip() clickEventConnection:disconnect() end

tool.Equipped:connect(onEquip) tool.Unequipped:connect(onUnequip)

1 answer

Log in to vote
0
Answered by
xdeno 187
6 years ago

Try

local clickEvent = tool:WaitForChild("RemoteEvent")

Often I find in game that your character loads before scripts, same happens with Humanoids in my case.

Ad

Answer this question