Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Firing a Remote Event after a function onActivated() for a tool?

This works in studio but not in published mode.

enabled = true

function onActivated()
	if not enabled  then
		return
	end

script.Parent.Activated:connect(function(plr)
		game.ReplicatedStorage.ballet1:FireServer() ---here is the problem, it functions in studio but doesn't want to function in published

end)

What the remote function is being told to do is put a simple print just to see if it's working and getting to that point or not (and it's not)

EDIT: I believe this is the problematic script that is not working correctly in published mode:

game.ReplicatedStorage.ballet1.OnServerEvent:Connect(function(plrWhoFiredEvent)

print("i got here")
end)

I've been trying out a couple of different things, here is another version of it that works in studio but not in published:

local hi = game.ReplicatedStorage.ballet1

function dothisplz()

print"i got here"
end

hi.OnServerEvent:connect(dothisplz)

I have FE on. :)

1 answer

Writing your code with the assumption that all the variables will already be loaded is a bad habit to make. For one, ReplicatedStorage is a service, which means the GetService() method must be used to call it. Also, checking to make sure ballet1 exists in the real game before doing anything with it is a good thing to do:

replicatedStorage = game:GetService("ReplicatedStorage")
enabled = true

function onActivated()
	if not enabled  then
		return
	end
end

script.Parent.Activated:connect(function(plr)
	local ballet1 = replicatedStorage:FindFirstChild("ballet1")
	ballet1:FireServer() --So I'm assuming your remote event is named ballet 1 and is in the replicated storage
end)

Hope that helps

7 comments

0

Thanks

0

Please accept answers :)

0

I wasn't on the computer yet I am testing it now

0

Can calling a remote function only work in a local script?

0

I'm guessing what's in my script in the ServerScriptService is what is causing the problem

0

The FireServer() function can only be called in a localscript, yes

0

Okay thanks, I just tested it in a local script instead but I think I have a broader issue than that. I posted my script for the response it's supposed to give for the remote function working. thank you for your help.

This discussion is preserved as it was. New answers, comments, and votes are closed.