local tween = require(game:GetService("ServerStorage").Modules.Tweening)
local httpService = game:GetService("HttpService")
local plr = game:GetService("Players").LocalPlayer
local add = require(game.ServerStorage.Modules.AddingItems)
script.Parent.MouseButton1Click:Connect(function()
print(plr.Name) -- if its just plr it will print 'nil'
local location = script.Parent.Parent
local pos1 = 0.5
local pos2 = 1.5
tween.out(plr, location, pos1, pos2)
add.BuyWeapons(2, plr)
end)
This is my current script and for some reason i get error saying āattempt to index nil with Nameā. Not sure what the problems is, Iāve tried many different ways and none of them work.
Iām not too sure what the module script does, and I donāt really need to know, but you should use a remote event, and have the click function in a local script.
You canāt get LocalPlayer in server scripts. Consider using a LocalScript, and use remotes to communicate with the server, or find another way to get the player.
local tween = require(game:GetService(āServerStorageā).Modules.Tweening)
local httpService = game:GetService(āHttpServiceā)
local add = require(game.ServerStorage.Modules.AddingItems)
script.Parent.MouseButton1Click:Connect(function(Player)
print(Player.Name) ā if its just plr it will print ānilā
local location = script.Parent.Parent
local pos1 = 0.
local pos2 = 1.5
tween.out(plr, location, pos1, pos2)
add.BuyWeapons(2, Player)
end)
Always use a LocalScript for UI related stuff. Also, LocalPlayer does not work in a regular script. All you need to change is that. Once you change it everything should work.
Just looking back into it and I just realised it said MouseButton1Click
use player and do
local tween = require(game:GetService("ServerStorage").Modules.Tweening)
local httpService = game:GetService("HttpService")
local add = require(game.ServerStorage.Modules.AddingItems)
game.Players.PlayerAdded:Connect(function(Player)
script.Parent.MouseButton1Click:Connect(function()
print(Player.Name) -- if its just plr it will print 'nil'
local location = script.Parent.Parent
local pos1 = 0.5
local pos2 = 1.5
tween.out(plr, location, pos1, pos2)
add.BuyWeapons(2, Player)
end)
end)
local tween = require(game:GetService(āServerStorageā).Modules.Tweening)
local httpService = game:GetService(āHttpServiceā)
local add = require(game.ServerStorage.Modules.AddingItems)
game.Players.PlayerAdded:Connect(function(Player)
script.Parent.MouseButton1Click:Connect(function()
print(Player.Name) ā if its just plr it will print ānilā
local location = script.Parent.Parent
local pos1 = 0.5
local pos2 = 1.5
tween.out(plr, location, pos1, pos2)
add.BuyWeapons(2, Player)
end)
end)
if thatās a server script then on the 3rd line you cant get .LocalPlayer because you can only get it through a local script so it returns Nil instead of the player