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

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

Asked by
Gingerely 245 Moderation Voter
4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago

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

0
when i make an OnServerEvent function, it does not do anything... Gingerely 245 — 4y
0
Did you change it to a local script? JayShepherdMD 147 — 4y
0
yes Gingerely 245 — 4y
0
the onserverevent function is in server script service Gingerely 245 — 4y
View all comments (8 more)
0
make sure you do game:GetService('ReplicatedStorage').Events:FindFirstChild('Sell').OnServerEvent:Connect(function(Player) JayShepherdMD 147 — 4y
0
not working Gingerely 245 — 4y
0
What do the errors say? JayShepherdMD 147 — 4y
0
nothing, i just did print("Working") after that and it wont print Gingerely 245 — 4y
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 JayShepherdMD 147 — 4y
0
yep... not workign Gingerely 245 — 4y
0
yep... not workign Gingerely 245 — 4y
0
Make sure your part is anchored. JayShepherdMD 147 — 4y

Answer this question