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

Cannot fire an event with a part touch, what is wrong ?

Can someone help i dont get it so every time i touch this part it warns me fireserver can only be called from the client

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.Events.Sell:FireServer()
		end
end)

2 answers

✓ Accepted answer

Hello Gingerely

Thanks for the question

Basically, because I guess you're using a server script, inside of a part, you can just do everything here, as the serverscript is safe, and the client can not edit this, meaining you will not need to fire the server.

RemoteEvents, allow the server and the Client to interact / communicate.

Since you're already using a serverscript, you can do this

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if debounce == false then -- checking for debounce
		debounce = true -- because player has touched.
		if hit.Parent:FindFirstChild("Humanoid") then -- has found a player.
			local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) -- gets the player inside of the 'Players' service.
			--Add the players currency here example;
			player.leaderstats["Currency2"].Value = player.leaderstats["Currency1"].Value * 2 --EXAMPLE.
			player["Currency1"].Value = 0 --EXAMPLE.
			wait(2)
			debounce = false
		end
	end
end)

This must be server script then, change it to a Local Script!

12 comments

0

when i make an OnServerEvent function, it does not do anything...

0

Did you change it to a local script?

0

yes

0

the onserverevent function is in server script service

0

make sure you do game:GetService('ReplicatedStorage').Events:FindFirstChild('Sell').OnServerEvent:Connect(function(Player)

0

not working

0

What do the errors say?

0

nothing, i just did print("Working") after that and it wont print

0

Make sure you have all your events in the right location, and make sure your server scripts are in serverscriptservice and your local script is in StarterGUI

0

yep... not workign

0

yep... not workign

0

Make sure your part is anchored.

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