dukeispieJoin Date: 2013-06-20 Post Count: 467 |
I was trying to create a shop featuring a camera that would rotate around the object the player was buying, but came across this:
local dBounce = false
function onclick(player)
if dBounce == false then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
end
if dBounce == true then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = player.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
end
return
end
script.Parent.MouseButton1Click:connect(onclick)
The Output it Gave me:
"Players.Player.PlayerGui.Shop.TextButton.Script:11: attempt to index local 'player' (a nil value)"
Any help? Thanks! |
|
llaserxJoin Date: 2011-12-10 Post Count: 53069 |
|
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
Changed the script to local player,
local dBounce = false
function onclick()
if dBounce == false then
local Player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
end
if dBounce == true then
local Player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = Player.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
end
return
end
script.Parent.MouseButton1Click:connect(onclick)
Doesn't give me any output but doesn't work. |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
bump |
|
llaserxJoin Date: 2011-12-10 Post Count: 53069 |
try
local dBounce = false
function onclick(player)
local plr = game.Players.LocalPlayer
if dBounce == false then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
end
if dBounce == true then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = plr.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
end
return
end
script.Parent.MouseButton1Click:connect(onclick)
http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$341 Tx536 (づ ゚ ³ ゚)づ |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
Still doesn't work, it seems as if you just renamed the variable which is no help. Anyone else? |
|
llaserxJoin Date: 2011-12-10 Post Count: 53069 |
|
|
|
it's not working because it's not a localscript
#Code print("Narwhals are our future") |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
When I tried making it a global it still didn't work. |
|
|
this is my best try
debounce = false
local p = game.Players.LocalPlayer
repeat wait() until p.Character ~=nil
local c = p.Character
local h = c:WaitForChild("Humanoid")
script.Parent.MouseButton1Down:connect(function()
if debounce == false then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
debounce = true
if debounce == true then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = h
cam.CameraType = "Custom"
wait(2)
debounce = false
end
end
end)
#Code print("Narwhals are our future") |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
Doesn't work.... AHHH WHAT'S WRONG?!?!?! |
|
|
my script isn't wrong
must be your hierarchy and whatnot
#Code print("Narwhals are our future") |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
What do you mean? It doesn't come up with any output and doesn't work. If I try this
local dBounce = false
script.Parent.MouseButton1Click:connect(function(player)
if dBounce == false then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
end
if dBounce == true then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = player.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
end
end)
on a Global that isn't wrong, but doesn't define player for some reason. |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
bump |
|
nitromonkJoin Date: 2014-11-22 Post Count: 23 |
Can someone teach me scripting???
Owner of doge inc. |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
bump |
|
|
local dBounce = false
script.Parent.MouseButton1Click:connect(function(player)
if dBounce == false then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
end
if dBounce == true then
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = player.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
end
end)
This will not define the player because MouseButton1Click does not pass in the player as an argument. First you need to remove the "player" from inside "function()" and put it at the top, under dBounce:
local player = game.Players.LocalPlayer
Then you need to make sure the thing you want it to focus on is called "ThingyOne" and it is in Workspace.
After that, you need to put this inside of a TextButton that is inside of a ScreenGui that is inside of StarterGui. |
|
dukeispieJoin Date: 2013-06-20 Post Count: 467 |
You have NO IDEA how many times people have told me that, when I do local player = game.Players.LocalPlayer inside a local script it does not work for some reason. |
|
|
Oh also, one more thing that literally makes the ENTIRE THING work: your script keeps reseting itself. Notice that at the end of the first condition it sets dBounce to true. Then the next condition checks if it's true and sets it back to false again. Your script never changes, it IMMEDIATELY resets itself. Here is the full fixed version I just got to work in Studio:
local dBounce = false
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
if dBounce == false then
print("False")
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.ThingyOne
cam.CameraType = "Custom"
dBounce = true
return
end
if dBounce == true then
print("True")
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = player.Character.Humanoid
cam.CameraType = "Custom"
dBounce = false
return
end
end) |
|
|
holy
MouseButton1Click does not return anything.
function getLocalPlayer()
c = script
repeat c = c.Parent until c:IsA("Player")
return c
end
player = getLocalPlayer
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
MouseButton1Click doesnt return anything.
MouseButton1Click:connect(function()
print(game.Players.LocalPlayer)
end) |
|