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

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

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

✓ Accepted answer

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)

3 comments

0

still wont work for some reason It doesnt print "Firedfromhandle" Im pretty sure its because of the local script

0

script.Parent is the tool correct?

0

Nevermind found my mistake but this did help with unnecessary stuff

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