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

Whats wrong with this script? It won't activate when clicked

Asked by 5 years ago

Honestly havn't scripted in a long time so it may be me but my research tells me Im doing something wrong or its just roblox being like that to me it wont even print "Firedfromhandle"

Script

local Player = game.Players.LocalPlayer

local PlayerName = Player.Name

function OnActivated()
    print("Firedfromhandle")
    game.ReplicatedStorage.Money.Add.Money["1$"]:FireServer(Player, PlayerName)
end

script.Parent.Activated:Connect(OnActivated)

Event

local FolderForDropMoney = game.ReplicatedStorage.Money.Add.Money
FolderForDropMoney["1$"].OnServerEvent:Connect(function(Player, PlayerName)
    print("Fired")
    if game.Workspace:FindFirstChild(PlayerName)["1"] then
        game.Workspace:FindFirstChild(PlayerName)["1"]:Destroy()
        Player.stats.Money.Value = Player.stats.Money.Value + 1
    end
end)

1 answer

Log in to vote
1
Answered by 5 years ago

I think that is because you are misunderstanding how remote events work, the first argument by default is the player who fired the event, you do not need to send that over, as for playername, you can just do Player.Character["1"]

local script

local Player = game.Players.LocalPlayer

local function OnActivated()
    print("Firedfromhandle")
    game.ReplicatedStorage.Money.Add.Money["1$"]:FireServer()
end

script.Parent.Activated:Connect(OnActivated)

Server script

local FolderForDropMoney = game.ReplicatedStorage.Money.Add.Money
FolderForDropMoney["1$"].OnServerEvent:Connect(function(Player)
    print("Fired")
    if Player.Character["1"] then
       Player.Character["1"]:Destroy()
        Player.stats.Money.Value = Player.stats.Money.Value + 1
    end
end)
0
still wont work for some reason It doesnt print "Firedfromhandle" Im pretty sure its because of the local script Sergiomontani10 236 — 5y
0
script.Parent is the tool correct? theking48989987 2147 — 5y
0
Nevermind found my mistake but this did help with unnecessary stuff Sergiomontani10 236 — 5y
Ad

Answer this question