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

FireClient not firing? (extra text to look like a question)

Asked by
Donut792 216 Moderation Voter
6 years ago

so i got this script that when a player presses a certain button if they have the right amount of experience it will fireclient and then it is supposed to take away that set amount of experience and set their speed value to true but it doesnt it also doesnt print any errors

script:

game.Players.PlayerAdded:Connect(function(plr)
local skill = plr.Experience.Skill
local speed = plr.Speed
script.Parent.Activated:Connect(function()
if skill.Value >=20000 then
    local Twenty = speed.Twenty.Value
    game.ReplicatedStorage.SpeedEvents.Twenty:FireClient(plr,Twenty)
else
    script.Parent.Parent.Parent.XpWarning.Visible = true
    wait(2.5)
    script.Parent.Parent.Parent.XpWarning.Visible = false
end
end)
end)

localscript:

game.ReplicatedStorage.SpeedEvents.Twenty.OnClientEvent:Connect(function(Twenty)
    game.Players.LocalPlayer.Experience.Skill.Value = game.Players.LocalPlayer.Experience.Skill.Value - 20000
    Twenty = true
end)

still quite new at remote events

0
it seems like you are trying to fire a value instead of a remote event theking48989987 2147 — 6y
0
yeah how do i do that? Donut792 216 — 6y

1 answer

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

With "FilteringEnabled" enabled, things change up a bit. And I'm pretty sure that you cannot change values using localscripts as only the client can see this and would probably cause issues.

Some of it needs re-editing and seeing that it's a tool your trying to use, your localscript should be the one firing a RemoteEvent rather than the other way around. Something to keep in mind is that when you fire a RemoteEvent or RemoteFunction, it will always give you the player who fired the RemoteEvent/RemoteFunction as the first parameter.

For your localscript, you don't need much code to run it since all your doing is activating your tool. Here's the simple localscript you need with some good notes (put it into the tool):

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.SpeedEvents.Twenty:FireServer()
    --Make sure that what you're firing is a RemoteEvent and *NOT* a RemoteFunction.
    --Also, you don't want any "if" statements in here because the "client" (or the user) can still fire the RemoteEvent whether if it meets the requirements or not (as an exploit issue fix)
end)

Your script is supposed to be the one doing all of the work (such as doing "if" statements and stuff). Also since the first parameter of your function is which player fired the RemoteEvent, you can use it to check for anything within it (it works like "game.Players.Localplayer") but you cannot use "game.Players.LocalPlayer" with a script since it runs on the server and not on the client so it wouldn't know which player your talking about. Here's the modified script:

game.ReplicatedStorage.SpeedEvents.Twenty.OnServerEvent:Connect(function(plr)
    local skill = plr.Experience.Skill
    local speed = plr.Speed

    if skill.Value >=20000 then
        plr.Experience.Skill.Value = plr.Experience.Skill.Value - 20000
        speed.Twenty.Value = true
    else
        script.Parent.Parent.Parent.XpWarning.Visible = true
        wait(2.5)
        script.Parent.Parent.Parent.XpWarning.Visible = false
    end
end) --The player is given always as the first parameter, even when you input parameters yourslef such as ":FireServer(money, exp)" and will always come out somthing like ".OnServerEvent:Connect(function(Player, money, exp)" 

If you have any questions or issues, please contact me. ;)

Ad

Answer this question